我需要在PHP中包含一些HTML内容,例如在这样的消息中添加<a href="#">link</a>
:
<?php
$to = $themail;
$subject = "Expiration d'une annonce";
$body = "Hey,\n\n";
// I need to include a link here in the body like <a href ="http://www.www.com"> Link </a>
mail($to, $subject, $body)
?>
有什么想法吗?
答案 0 :(得分:4)
我建议使用PHPMailer,易于使用,负责所有nesseccery标头,轻松附件发送,多个收件人等。
答案 1 :(得分:2)
这是非常基本的:mail()
设置正确的标题(来自php.net)
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
您的$ message现在可能包含HTML。对于复杂的html /电子邮件,建议查看一些包,例如PEAR Mailer类。
答案 2 :(得分:1)
我不明白。你需要像这样回应html吗?
echo '<a href ="http://www.www.com"> Link </a>';
或者你需要这样做:
$body .= '<a href ="http://www.www.com"> Link </a>';
你究竟想做什么?
如果您尝试通过mail()发送HTML数据,则需要设置几个标题
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf8' . "\r\n";
mail($to, $subject, $body, $headers);
有关详情,请查看http://php.net/manual/en/function.mail.php 示例4
答案 3 :(得分:1)
php.net/mail有很多例子
<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
我还发现这篇文章很有用: