dongzhui9936 2014-03-24 02:13
浏览 45
已采纳

PHP发送电子邮件包含HTML

I tried many tutorials, but still cannot work.

Here is my PHP code for send email :

$from = "Someone <someone@example.com>";
$to = "Someone 1 <someone1@example.com>";
$subject = "Test Send Email";
$body = "<div>Test</div>";

$host = "mail.example.com";
$username = "someone";
$password = "blabla";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail))
{
    echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
    echo("<p>Message successfully sent!</p>");
}

Once I got that email message, will keep show with HTML code like this :

<div>Test</div>

Any advice?

  • 写回答

1条回答 默认 最新

  • dongtang6681 2014-03-24 02:16
    关注

    Add the HTML Header:

    $headers = array(
        'From'          => $from,
        'To'            => $to,
        'Subject'       => $subject,
        'Content-Type'  => 'text/html; charset=UTF-8'
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半