参见英文答案 > Send HTML in email via PHP? 8个
我正在通过PHP的mail()函数发送电子邮件.在消息中,我设置了一个如下所示的链接:
$message = "" .$title. "\n\n";
但是,当收到电子邮件时,电子邮件正文显示html代码而不是标题作为超链接.我对html电子邮件不是很熟悉.我怎么能实现我想要的目标呢?
解决方法:
尝试添加标头,以便邮件客户端不相信它是纯文本:
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
示例#4发送HTML电子邮件:
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
Birthday Reminders for AugustHere are the birthdays upcoming in August!
Person | Day | Month | Year |
---|---|---|---|
Joe | 3rd | August | 1970 |
Sally | 17th | August | 1973 |
';
// 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 , Kelly ' . "\r\n";
$headers .= 'From: Birthday Reminder ' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
标签:html,php
来源: https://codeday.me/bug/20190927/1823638.html