在我的网站中,我有一个 PHP 脚本,可以自动向我的客户发送有关订单的确认信息。
我的网站的域名也注册到了托管我的网站的公司。
我在使用 mail() 函数向某些电子邮件帐户发送电子邮件时遇到很多问题......我的很多用户联系我说他们从未收到过我的自动电子邮件!所以这是一个非常大的问题!
给我带来更多问题的帐户是 comcast.net、uol.com、mchsi.com 等!我已经联系了这些电子邮件服务提供商的支持中心,要求将我的 IP 地址也从阻止列表中删除。
电子邮件的标题如下所示:
$header = "Sender: $from_mail\n";
$header .= "From: Account <$from_mail>\n";
$header .= "Reply-To: Account <$from_mail >\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\n";
$header .= "Mime-Version: 1.0\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";
$body = "\n--$mixed_boundary\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
我可以尝试避免此问题吗?
有人知道我在哪里可以知道 PHP mail() 函数用于发送电子邮件的服务器的 IP 地址是什么?
预先感谢您的回复!
您好,
今天仍然有一些电子邮件提供商服务(例如 Comcast)继续阻止我的 IP 地址,说我的邮件服务器发送垃圾邮件...我请求从阻止列表中删除,但他们的系统继续阻止它们!我不知道我还能做什么...我已遵循您的建议,代码如下所示:
$md5 = md5(date('r', time()));
$mixed_boundary = "PHP-Mixed-$md5";
$alt_boundary = "PHP-Alt-$md5";
$header = "Sender: $from_mail\r\n";
$header .= "Errors-To: $from_mail\r\n";
$header .= "From: account <$from_mail>\r\n";
$header .= "Reply-To: $from_mail\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\r\n";
$header .= "Mime-Version: 1.0\r\n";
$header .= "X-Mailer: PHP/".phpversion()."\r\n";
$body = "\n--$mixed_boundary\n";
$body .= "Content-Type: multipart/alternative; boundary=$alt_boundary\n";
.
.
.
.
$body .= "--$mixed_boundary\n";
$body .= "Content-Disposition: attachment filename=\"...\"\n";
$body .= "Content-Type: application/octet-stream; x-unix-mode=0644; name=\"...\"\n";
$body .= "Content-Transfer-Encoding: base64\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
建议?
再次感谢!
in my website i've a PHP script that automatically mails to my customers a confirmation about the order.
My website's domain is registered to a company that hosts my website too.
I have a lot of problems to send e-mails using mail() function to some e-mails accounts ... a lot of my users contact me saying that they have never received my automatic e-mail! So this is a very big problem!
The accounts, that give me more problems, are comcast.net, uol.com, mchsi.com and others! I've contacted the support center of these e-mail service providers asking for removing my ip from the block list too.
The header of the e-mail looks like this:
$header = "Sender: $from_mail\n";
$header .= "From: Account <$from_mail>\n";
$header .= "Reply-To: Account <$from_mail >\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\n";
$header .= "Mime-Version: 1.0\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";
$body = "\n--$mixed_boundary\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
There is something that I can try to avoid this problem?
Someone knows where can I look to know what is the IP address of the server used to deliver e-mails thought the PHP mail() function?
Thanks in advance for your replies!!!
Hi,
still today some e-mail provider service such as Comcast, continue to block my IPs addresses saying that my mail server sends spams ... I requested the removing from the blocklist, but their system continue block them! I don't know what else can I do ... I've followed your suggestions and the code look like this:
$md5 = md5(date('r', time()));
$mixed_boundary = "PHP-Mixed-$md5";
$alt_boundary = "PHP-Alt-$md5";
$header = "Sender: $from_mail\r\n";
$header .= "Errors-To: $from_mail\r\n";
$header .= "From: account <$from_mail>\r\n";
$header .= "Reply-To: $from_mail\r\n";
$header .= "Content-Type: multipart/mixed; boundary=$mixed_boundary\r\n";
$header .= "Mime-Version: 1.0\r\n";
$header .= "X-Mailer: PHP/".phpversion()."\r\n";
$body = "\n--$mixed_boundary\n";
$body .= "Content-Type: multipart/alternative; boundary=$alt_boundary\n";
.
.
.
.
$body .= "--$mixed_boundary\n";
$body .= "Content-Disposition: attachment filename=\"...\"\n";
$body .= "Content-Type: application/octet-stream; x-unix-mode=0644; name=\"...\"\n";
$body .= "Content-Transfer-Encoding: base64\n";
.
.
.
.
$body .= "\n\n--$mixed_boundary--";
mail($to, $subject, $body, utf8_encode($header), "-f$from_mail");
Suggestions?
Thanks again!
发布评论
评论(6)
让我解释一下你所面临的战斗。暂时忘记技术细节。
那里有数百家电子邮件提供商。最大的服务包括 Yahoo、Gmail、AOL、Hotmail 等。如果您被阻止使用这些服务中的任何一个,您的业务可能会受到严重影响。
这些电子邮件提供商非常担心垃圾邮件,并且为了打击垃圾邮件,他们已经采取了极端措施来阻止任何可能是垃圾邮件的邮件。您可能永远不会收到垃圾邮件投诉,但如果您的共享托管计划中的其他企业收到垃圾邮件投诉,您将受到影响。如果您使用的是可疑垃圾邮件 IP 地址,则无论您如何配置应用程序,您的邮件都会被发送到垃圾邮件文件夹。
即使您拥有自己的服务器,您仍然会遇到问题。随着时间的推移,如果您发送电子邮件,一些收件人会点击垃圾邮件按钮。这是生活中的事实,您无法阻止它。
唯一的解决方案是外包您的电子邮件发送。 Aweber 或 iContact 等公司为您处理电子邮件传送问题。他们与所有主要电子邮件提供商都有关系,并努力确保您的邮件进入收件人的收件箱。
您不再需要担心因为有人点击垃圾邮件按钮而联系 Yahoo 或 Gmail。您可以专注于更重要的事情。
Let me explain the battle you are facing. Forget about the technical details for a minute.
There are hundreds of email providers out there. The big ones are Yahoo, Gmail, AOL, Hotmail, etc. If you are blocked on anyone of these services your business could be severely affected.
These email providers are extremely concerned about spam and in order to combat spam have gone to the extreme of blocking any messages that might be spam. You might never get spam complaints but if another business, on your shared hosting plan, gets spam complaints you will be effected. It doesn’t matter how you configure your application if you are on a suspected spam IP address your messages will be sent to the spam folder.
Even if you have your own server you will still have issues. Over time if you send emails some of the recipients will hit the spam button. This is a fact of life and there is nothing that you can do to prevent it.
The only solution is to outsource you email delivery. Companies like Aweber or iContact deal with email delivery issues for you. They have relationships with all major email providers and work hard to ensure that your messages get into the recipients inbox.
You no longer have to worry about contacting Yahoo or Gmail because someone hit the spam button. You can focus on more important things.
根据 RFC2822 Internet 消息格式,您的消息标头无效。
从2.1概述:
正如我在评论中指出的那样,您的电子邮件可以与大多数邮件服务器一起使用的原因是它们在接受的内容上可能是自由的。但是,某些邮件服务器可能会丢弃您的邮件,因为它们不符合 RFC2822。
编辑:虽然在 mail() 函数的 PHP 文档中提倡使用“\r\n”,但有一些 争论这是否真的是正确的做法。
mail() 函数将与本地 sendmail(8) 命令通信(或 sendmail_path 中配置的任何内容),并且根据使用的邮件传输代理实现,行结尾可能会以不同的方式处理。据我了解, sendmail(8) 应该可以使用“\r \n",但例如 qmail(7) 将替换“\r\n ” 与“\r\r\n”,这可能会破坏消息。
这一切都发生在电子邮件发送到最终目的地之前,因此可以通过向自己发送由“\r\n”构造的电子邮件消息并验证所有标头是否存在来轻松测试行结尾是否已正确处理。
另请参阅:RFC2822、PHP mail() 函数, sendmail(8), qmail(7)
Your message headers are not valid according to RFC2822 Internet Message Format.
From 2.1 General Description:
As I pointed out in my comments, the reason why your email may work with most mail servers anyway is that they may be liberal in what they accept. There may be some mail servers, however, that will discard your messages since they don't comply with RFC2822.
EDIT: Although the use of "\r\n" is advocated in the PHP documentation for the mail() function, there is some debate about whether that's really the right thing to do.
The mail() function will communicate with the local sendmail(8) command (or whatever is configured in sendmail_path), and the line endings may be processed differently depending on what mail transfer agent implementation is used. From what I understand, sendmail(8) should be OK with "\r\n", but qmail(7) for example will replace "\r\n" with "\r\r\n", which will probably break the message.
This all happens before the email is delivered to its final destination, so it may be easily tested whether the line endings are processed properly by sending one's self an email message constructed with "\r\n" and by verifying that all headers are present.
See also: RFC2822, PHP mail() function, sendmail(8), qmail(7)
您可以给自己发送一封电子邮件并检查标题。这将使您了解电子邮件可能采用的路径,但实际上没有什么可以阻止发送到其他域的电子邮件通过不同的路径。
一般来说,那些大型 ISP 拥有非常强大的垃圾邮件过滤器,因此从共享主机向他们发送邮件将会很困难。如果您可以获得自己的 IP 地址并从那里发送邮件,这可能会有所帮助。然后您可以设置SPF记录。不能保证,但这肯定会让您摆脱商业垃圾邮件发送者的困境。
您还可以使用链接文本和其他一些反垃圾邮件服务进行一些挖掘,看看您是否做任何其他错误的事情。
要求客户将您的发件人地址添加到他们的垃圾邮件白名单中可能也没有什么坏处。
You could send yourself an email and check the headers. That will give you an idea of the path an email might take, but there's really nothing preventing emails to those other domains from going through a different path.
In general those big ISP's have really heavy duty spam filters, so mailing to them from a shared host is going to be tough. If you can get your own IP address and send mail from there, it will probably help. Then you can set up SPF records. No guarantees, but that will definitely elevate you out of the pit of commercial spammers a bit.
You could also do some digging with link text and some of the other anti-spam services and see if you're doing anything else wrong.
Asking customers to add your from address to their spam whitelist probably wouldn't hurt either.
我发现设置
Return-Path
、Sender
和Errors-To
标头在某些情况下会有所帮助。I've found that setting
Return-Path
,Sender
, andErrors-To
headers help in some cases.使用 PHPMailer (http://phpmailer.worxware.com/) 构建电子邮件消息。也许不是IP,而是其他东西。在很多情况下,垃圾邮件过滤器都会产生过敏反应(例如缺少消息 ID 等)。另外,使用 PHPMailer,您可以通过 mail() 发送邮件,或者如果由于共享主机问题而无法通过其他主机(如 Gmail)通过 SMTP 发送邮件。
Use PHPMailer (http://phpmailer.worxware.com/) for building the email-messages. Maybe it's not the IP, but something else. There are a lot of things, where spamfilters react allergic (like missing Message-ID etc.). Plus with PHPMailer you have the opportunity to send your mails via mail() or if it dont't work due to shared-hosting-problems via SMTP over an other host (like Gmail).
我注意到,在我的 Linux 托管服务器上,我必须在额外标头和混合/替代标头中将所有出现的 CRLF 替换为 LF。关于PHP文档说:
“如果没有收到消息,尝试仅使用 LF (\n)。一些质量较差的 Unix 邮件传输代理会自动将 LF 替换为 CRLF(如果使用 CRLF,则会导致 CR 重复),因为它不符合 » RFC。 2822."
我尝试向我的个人帐户发送一封邮件(仅包含“\n”),并且我在原始消息中查找了“\r”和“\n”...该行以 CR 结束并以“\n”开始!
问题: 正如 PHP mail() 文档所述,我使用函数 wordwrap() 将行长度缩短为 70 个字符。
有一种解决方法可以让邮件客户端以其原始格式显示消息,而不是显示为每行不超过 70 个字符的列?
答案[解决方案]:我已经解决了将quoted-printable设置为Content-Transfer-Encoding的问题:
quoted_printable_encode()函数仅适用于PHP 5.3,该实现适用于文档页面。
I've noticed that with my Linux hosting server, I have to replace all occurrences of CRLF with LF in both the extra headers and the mixed/alternative headers. About that the PHP documentation says:
"If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822."
I've tried to send a mail (only with "\n") to my personal account and I've looked for "\r" and "\n" in the raw message ... each line is ended by a CR and started with a "\n"!
QUESTION: As the PHP mail() documentation says, I use the function wordwrap() to cut the line length to 70 characters.
There is a workaround to let the mail client to display the message with its original formatting and not as a column where each line isn't longer than 70 chars?
ANSWER [SOLUTION]: I have solved setting up quoted-printable as Content-Transfer-Encoding:
The quoted_printable_encode() function is available only with PHP 5.3, the implementation is suitable in the documentation page.