加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

来自php.net手册的mail():“to”和“to-header”之间的区别

发布时间:2020-12-13 18:00:53 所属栏目:PHP教程 来源:网络整理
导读:在mail.net的php.net示例中,两个不同的地址用于$to和附加的头信息“To:…”: ?php// multiple recipients$to = 'aidan@example.com' . ','; // note the comma$to .= 'wez@example.com';$subject = 'Birthday Reminders for August';// message$message =
在mail.net的php.net示例中,两个不同的地址用于$to和附加的头信息“To:…”:
<?php
// multiple recipients
$to  = 'aidan@example.com' . ','; // note the comma
$to .= 'wez@example.com';

$subject = 'Birthday Reminders for August';

// message
$message = '<html> ... </html>';

// To send HTML mail,the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

// Additional headers
$headers .= 'To: Mary <mary@example.com>,Kelly <kelly@example.com>' . "rn";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "rn";
$headers .= 'Cc: birthdayarchive@example.com' . "rn";
$headers .= 'Bcc: birthdaycheck@example.com' . "rn";

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

所以我的问题是:你需要为mail()的语法提供$to,但是你不能使用格式Name< email@domain.comu0026gt;,这只能在附加的头信息中做,对吧? 首先,为什么php.net上的示例会将邮件发送给4个不同的人(因为他们使用不同的电子邮件地址来获取$to和标题信息),这真的让我很恼火!? 其次,如果我想将邮件仅发送给1个人(并且只有1次),并且我想使用格式名称< email@domain.comu0026gt;,我应该怎么做?在$to中使用它以及标题信息?然后这个人会收到两次电子邮件吗?

建议您使用 PHP Mailer类而不是内部mail()函数.使用 PHP Mailer有几个原因:

>使用自己的smtp的能力>更好的机会不被列入垃圾邮件(主要原因)>易于使用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读