【问题标题】:PHP mail(); Send e-mail as plain text AND a HTMLPHP 邮件();以纯文本和 HTML 格式发送电子邮件
【发布时间】:2017-06-28 19:27:42
【问题描述】:

我有以下 PHP 代码,用于使用 PHP mail() 作为 HTML 发送电子邮件:

<?php
    $to = "test@example.com";

    $subject = "This is the subject";

    $headers = "From: Me<test@exapmle.com>\r\n";
    $headers .= "Return-Path: test@exapmle.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $headers .= "X-Priority: 1\r\n";

    $message = "This is my <b>message</b>!";

    mail($to,$subject,$message,$headers);
?>

但我想支持纯文本和 HTML。 HTML 用于粗体和纯文本等内容,以在不支持 html 的电子邮件客户端中显示 This is my message! 而不是 This is my &lt;b&gt;message&lt;/b&gt;!

我该怎么做?

我读到了边界。这就是我要找的吗?但如果是这样,如何使用它?没看懂。

【问题讨论】:

  • 是的,边界是您需要的一部分。您可以在此处查看有关如何执行您想要执行的操作的完整示例和说明:stackoverflow.com/questions/10267840/…
  • @BenShoval 我已经找到了这个,但我不明白。
  • @David:你到底有什么不明白的?
  • 为什么不直接使用 phpmailer 或 swiftmailer?

标签: php html email boundary


【解决方案1】:

我强烈建议您使用现有的库,例如 PHPMailer (https://github.com/PHPMailer/PHPMailer),它可以满足您的所有需求,甚至更多。

$mail = new PHPMailer;
$mail->isHTML(true);
$mail->Body = '<b>Html body</b> here.';
$mail->AltBody = 'Normal text here.';

【讨论】:

  • 我不喜欢图书馆。
猜你喜欢
  • 2012-04-29
  • 1970-01-01
  • 2021-04-12
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 2015-07-13
  • 2010-11-26
相关资源
最近更新 更多