使用php邮件功能防止发送的邮件被视为垃圾邮件
我写了一个 PHP 脚本来发送电子邮件。
我的脚本是这样的:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
// Email Variables
$toUser = "[email protected]"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
嗯,当然我为发件人和收件人使用有效的电子邮件地址。 我确实收到了这封电子邮件,但它变成了垃圾邮件。 所以我去谷歌研究。 是因为我的“标题”脚本问题吗? 如果不是,那么什么可能导致我的脚本发送垃圾邮件? 有什么解决办法吗?
I wrote a PHP script to send emails.
My script is like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
// Email Variables
$toUser = "[email protected]"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
请尝试这个:
Please try this:
也许问题是雅虎使用 domainkeys 验证,考虑到邮件,您的应用程序可能会失败实际上并不是来自雅虎的服务器。
Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.
当我曾经遇到过类似的问题时,我查看了标头,发现我的主机使用 SpamAssassin。 因此,我在谷歌上搜索“SpamAssassin 分数”,找到了大量有关如何错误(从而正确)形成电子邮件的信息。
例如:SpamAssassin 分数列表
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
1. 检查邮件内容
正如其他人暗示的那样,它可能被标记为垃圾邮件,因为您的邮件看起来像垃圾邮件。
我不确定您发布的脚本是否是您正在测试的实际脚本。
如果它有实际的邮件正文& 标头,然后通过 SpamAssassin 标准安装运行此邮件,其垃圾邮件分数为 4.9。
由于电子邮件正文仅包含 HTML,因此大多数反垃圾邮件解决方案更有可能对它进行可疑处理。
2. 邮件服务器的 IP
另一个值得检查的方面是邮件服务器的 IP 地址。 任何源自动态 IP 地址的邮件都可能被视为垃圾邮件。
3. 阻止列表
另请检查您的 IP 地址是否列在阻止列表之一中。 首先,请使用 http://www.spamhaus.org/lookup.lasso。
1. Check mail content
As others have hinted it is probably marked as spam because your mail looks like spam.
I am not sure if you the script that you have posted is the actual one that you are testing.
If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9
Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.
2. Mail server's IP
Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.
3. Blocklists
Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.
使用mxtoolbox.com检查服务器IP是否被列入黑名单。 该网站还可以帮助您进行一些与电子邮件相关的检查。
当然,垃圾邮件过滤器内部运行着一长串检查。 正如已经建议的,检查电子邮件标题以获取有关垃圾邮件的垃圾邮件过滤器评级的详细信息。
希望有帮助!
Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.
Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.
Hope that helps!
我遇到了同样的问题:
问题是,当您在“发件人:”部分之前指定内容类型时,邮件会成为垃圾邮件。
但是,如果您在内容部分之前指定“发件人:”,它将作为普通邮件发送,让您微笑并感到好奇。
I was having the same problem:
The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.
But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.
正如 schnalle 所说,一个问题肯定是您用来发送电子邮件的 smtp 服务器和您指定的发件人服务器是不同的。发件人的域应该与您正在运行的服务器相同。
所以,你可以使用yahoo服务器通过smtp连接发送电子邮件(检查他们是否允许smtp远程连接,但我猜他们是这样做的),这将解决1个问题。
另一种是没有替代纯文本内容的 html 内容,但是,这个不太重要。
我建议你phpMailer,免费开源的php类发送电子邮件,轻松发送到使用(我使用它事件o通过gmail服务器发送邮件)
As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.
So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.
Another one is the html contents without the alternative plain text contents, but, this one is less important.
I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)
这些是您可以尝试的基本操作。
These are the basic things you can try.
如果您的网站域名是 mydomain.com,则在“发件人”标头中,请确保使用 [电子邮件受保护]
if your website domain is mydomain.com then in From headers make sure to use [email protected]
删除
Content-type: text/html
并添加$headers .= "X-Priority: 2\nX-MSmail-Priority: high";
以消除垃圾邮件。 此方法已经过尝试和测试。Remove the
Content-type: text/html
and add$headers .= "X-Priority: 2\nX-MSmail-Priority: high";
to get rid of Spam. This method has been tried and tested.问题是,您发送邮件的服务器不是雅虎服务器。 大多数垃圾邮件过滤器都会检查它们是否匹配,否则将(并且现在或曾经)可以轻松伪造发件人。 有没有想过为什么您会收到来自 bill.gates AT microsoft.com 或您自己的邮件地址的垃圾邮件?
the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?
您有两种解决方案:
You've got two solutions:
您可以尝试我在这里创建的邮件类和测试文件。 我已经测试了这些文件,并且可以使用不同的邮件名称将电子邮件发送到我的 hotmail 和 gmail。 电子邮件被标记为垃圾邮件的主要原因是结构(标题和消息)未正确完成。 在大多数情况下,换行是导致问题的原因。
我可以使用它向 Gmail 发送带有附件的邮件。 但是,这些附件不适用于 hotmail。 希望这有帮助 =)
您可以在 此处检查文件..
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..