简体   繁体   English

PHP将带有标头的邮件发送到Gmail

[英]PHP Sending Mail with Headers to Gmail

The mail() function in PHP works fine when sending to Gmail if I don't specify any headers. 如果我未指定任何标头,则在发送到Gmail时,PHP中的mail()函数可以正常工作。 However, as soon as I try to add in headers, the function still returns true but I never get the email. 但是,当我尝试添加标题时,该函数仍然返回true但我从未收到电子邮件。 The Gmail server seems to reject the delivery. Gmail服务器似乎拒绝了传递。

These are the headers I'm using: 这些是我正在使用的标头:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $username . ' <' . $email . '>' . "\r\n";
$headers .= 'From: Blahblah <email@example.com>' . "\r\n";
mail($email, 'Subject', '<html><body>Body of message</body></html>', $headers);

I was hoping that someone could point out to me the flaw? 我希望有人可以指出我的缺陷? I grabbed most of this code straight from the PHP manual, so one could understand my confusion and frustration. 我直接从PHP手册中获取了大部分代码,因此可以理解我的困惑和沮丧。 Thanks! 谢谢!

The bigger email services will not deliver mail sent from your own personal server in this manner. 较大的电子邮件服务不会以这种方式传递从您自己的个人服务器发送的邮件。
Due to SPAM issues. 由于垃圾邮件问题。 All the big mail providers require SPF records, DKIM, and reverse DNS before they will accept your mail. 所有大型邮件提供商都需要SPF记录,DKIM和反向DNS,然后才能接受您的邮件。

Some live/hotmail user's are not receiving html mail 一些实时/ hotmail用户未收到html邮件

Personally I prefer to be rid of that hassle and use a 3rd party mail server for all of my outgoing mails to my users. 就我个人而言,我更希望摆脱这种麻烦,并使用第三方邮件服务器来处理所有发给用户的邮件。

$Headers .= "From: $Yourname <$YourEmail>\r\n"; 

or 要么

$Headers .= 'From: '.$Yourname.'<'.$Youremail.'>'."\r\n"; 

or 要么

$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";

Give a try if any of this work? 试试看是否有这项工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM