有人告诉我为什么当我尝试从php脚本发送html邮件时。我的前景与我在数据库中看到的一样接收它吗?
目前,我的工具会发送一封电子邮件,其中$body
var为<p>Dear client,</p> <p> </p> <p>Please find your account statement attached.</p> <p> </p> <p>Kind Regards</p>
代码:
$email = new PHPMailer();
$email->From = $from_email_address;
$email->FromName = $from_name;
$email->Subject = $subject;
$email->IsHTML(true);
$email->Body = $body;
$email->AddAddress($client_email);
$email->AddAttachment(ROOTDIR.'/reports/statement.pdf', "Statement.pdf");
echo $email->Send();
但是当outlook收到电子邮件时,它的格式不像html代码所要求的那样。 Outlook仅显示原始代码中的<p>
标记。
P.S:
我注意到,如果我添加此行:$body='<p>Dear client,</p><p>Please find this email well</p>';
电子邮件是在html中生成并正确显示。但是当它从数据库<p>Dear client,</p> <p> </p> <p>Please find your account statement attached for your company.</p> <p> </p> <p>Kind Regards</p>
加载此值时,它会将代码作为文本发送。不会将其转换为HTML。
导致这种情况的原因是什么?
答案 0 :(得分:0)
为HTML内容添加电子邮件标头
$email = new PHPMailer();
$email->headers = 'MIME-Version: 1.0' . "\r\n";
$email->headers.= 'Content-type: text/html; charset=us-ascii' . "\r\n";
$email->From = $from_email_address;
$email->FromName = $from_name;
$email->Subject = $subject;
$email->IsHTML(true);
$email->Body = $body;
$email->AddAddress($client_email);
$email->AddAttachment(ROOTDIR.'/reports/statement.pdf', "Statement.pdf");
echo $email->Send();