【发布时间】: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 <b>message</b>!。
我该怎么做?
我读到了边界。这就是我要找的吗?但如果是这样,如何使用它?没看懂。
【问题讨论】:
-
是的,边界是您需要的一部分。您可以在此处查看有关如何执行您想要执行的操作的完整示例和说明:stackoverflow.com/questions/10267840/…。
-
@BenShoval 我已经找到了这个,但我不明白。
-
@David:你到底有什么不明白的?
-
为什么不直接使用 phpmailer 或 swiftmailer?