使用php邮件功能防止作为垃圾邮件处理的已发送电子邮件

时间:2022-10-23 18:03:53

I wrote a PHP script to send emails.

我写了一个PHP脚本来发送电子邮件。

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: abc@yahoo.com' . "\r\n";

// Email Variables
$toUser  = "someone@yahoo.com"; // 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?

好吧,当然我使用有效的电子邮件地址发送者和接收者。我确实收到了电子邮件,但它是垃圾邮件。所以我去了谷歌研究。是因为我的“标题”脚本问题?如果不是,那么什么可能导致我的脚本发送垃圾邮件?有解决方案吗

14 个解决方案

#1


11  

Please try this:

请试试这个:

$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";

mail($to,$subject,$body,$headers,"-f$from");

#2


8  

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.

也许问题是雅虎使用了域密钥验证,鉴于邮件实际上并非来自雅虎的服务器,这可能会对您的应用程序失败。

#3


7  

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.

当我遇到类似的问题时,我查看了标题,发现我的主机使用了SpamAssassin。因此,我搜索了“SpamAssassin得分”,并发现了大量关于如何错误(并因此正确)形成电子邮件的信息。

For example: SpamAssassin score list

例如:SpamAssassin得分列表

#4


5  

1. Check mail content

1.检查邮件内容

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

如果它有实际的邮件正文和标题,那么通过SpamAssassin的标准安装运行此邮件会使垃圾邮件得分为4.9

X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
        HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
        version=3.2.5

Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.

由于电子邮件正文只有HTML,因此大多数反垃圾邮件解决方案更有可能被嫌疑人处理。

2. Mail server's IP

2.邮件服务器的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.

值得检查的另一个方面是您的邮件服务器的IP地址。源自动态IP地址的任何邮件都可能被视为垃圾邮件。

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.

还要检查您的IP地址是否列在其中一个阻止列表中。首先,请通过http://www.spamhaus.org/lookup.lasso检查您的IP地址。

#5


3  

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.

使用mxtoolbox.com检查要列入黑名单的服务器IP。此网站也可以帮助您进行几个与电子邮件相关的检查。

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!

希望有所帮助!

#6


3  

                   **This Works Perfectly fine for me**     
                        $to="reciever@reciever.com";
                        $subject="This is Your Message";
                        $from = 'Sender <noreply@sender.com>';
                        $body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
                        $headers = "From: " .($from) . "\r\n";
                        $headers .= "Reply-To: ".($from) . "\r\n";
                        $headers .= "Return-Path: ".($from) . "\r\n";;
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                        $headers .= "X-Priority: 3\r\n";
                        $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
                        mail($to,$subject,$body,$headers);

#7


2  

if your website domain is mydomain.com then in From headers make sure to use someone@mydomain.com

如果您的网站域名是mydomain.com,那么在From头文件中请确保使用someone@mydomain.com

#8


2  

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.

但是如果你在内容部分之前指定“发件人:”它就像普通邮件一样,让你微笑和好奇。

#9


1  

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.

正如schnalle所说,一个问题肯定是你用来发送电子邮件的smtp服务器和你指定为From的那个服务器是不同的...来自域的域应该与你运行的服务器相同。

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.

因此,您可以使用yahoo服务器发送电子邮件(检查是否允许smtp远程连接,但我猜他们这样做)通过smtp连接,这将解决1个问题。

Another one is the html contents without the alternative plain text contents, but, this one is less important.

另一个是没有替代纯文本内容的html内容,但是,这个内容不太重要。

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)

我建议你phpMailer,免费和开源php类发送电子邮件,轻松使用(我用它事件o通过gmail服务器发送邮件)

#10


1  

  1. On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
  2. 在您的服务器上尝试将SPF(发件人策略框架,Google for SPF记录)记录排序。

  3. Make sure you send your e-mails from an existing account on your server/domain.
  4. 确保从服务器/域上的现有帐户发送电子邮件。

  5. Make sure you have the reply-to address in your header.
  6. 确保标题中有回复地址。

These are the basic things you can try.

这些是您可以尝试的基本内容。

#11


1  

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.

删除Content-type:text / html并添加$ headers。=“X-Priority:2 \ nX-MSmail-Priority:high”;摆脱垃圾邮件。已经尝试并测试了该方法。

#12


0  

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?

问题是,你发送邮件的服务器不是雅虎服务器。大多数垃圾邮件过滤器检查它们是否匹配,否则它(并且是 - 或者是)可以轻易伪造发件人。曾经想知道为什么你从bill.gates AT microsoft.com或你自己的邮件地址收到垃圾邮件?

#13


0  

You've got two solutions:

你有两个解决方案:

  • use Yahoo's SMTP using abc@yahoo.com credentials to send mail from abc@yahoo.com;
  • 使用Yahoo的SMTP使用abc@yahoo.com凭据从abc@yahoo.com发送邮件;

  • use other from, with your own domain;
  • 使用其他来自您自己的域名;

#14


0  

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.

您可以尝试我在此处创建的邮件类和测试文件。我测试了这些文件,可以使用不同的邮件名称向我的hotmail和gmail发送电子邮件。电子邮件标记为垃圾邮件的主要原因是因为结构(标题和邮件)未正确完成。在大多数情况下,导致问题的是换行。

I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)

我可以使用它将包含附件的邮件发送到Gmail。但是,附件不适用于hotmail。希望这有助于=)

You can check the files here..

你可以在这里查看文件..

#1


11  

Please try this:

请试试这个:

$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";

mail($to,$subject,$body,$headers,"-f$from");

#2


8  

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.

也许问题是雅虎使用了域密钥验证,鉴于邮件实际上并非来自雅虎的服务器,这可能会对您的应用程序失败。

#3


7  

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.

当我遇到类似的问题时,我查看了标题,发现我的主机使用了SpamAssassin。因此,我搜索了“SpamAssassin得分”,并发现了大量关于如何错误(并因此正确)形成电子邮件的信息。

For example: SpamAssassin score list

例如:SpamAssassin得分列表

#4


5  

1. Check mail content

1.检查邮件内容

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

如果它有实际的邮件正文和标题,那么通过SpamAssassin的标准安装运行此邮件会使垃圾邮件得分为4.9

X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
        HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
        version=3.2.5

Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.

由于电子邮件正文只有HTML,因此大多数反垃圾邮件解决方案更有可能被嫌疑人处理。

2. Mail server's IP

2.邮件服务器的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.

值得检查的另一个方面是您的邮件服务器的IP地址。源自动态IP地址的任何邮件都可能被视为垃圾邮件。

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.

还要检查您的IP地址是否列在其中一个阻止列表中。首先,请通过http://www.spamhaus.org/lookup.lasso检查您的IP地址。

#5


3  

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.

使用mxtoolbox.com检查要列入黑名单的服务器IP。此网站也可以帮助您进行几个与电子邮件相关的检查。

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!

希望有所帮助!

#6


3  

                   **This Works Perfectly fine for me**     
                        $to="reciever@reciever.com";
                        $subject="This is Your Message";
                        $from = 'Sender <noreply@sender.com>';
                        $body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
                        $headers = "From: " .($from) . "\r\n";
                        $headers .= "Reply-To: ".($from) . "\r\n";
                        $headers .= "Return-Path: ".($from) . "\r\n";;
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                        $headers .= "X-Priority: 3\r\n";
                        $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
                        mail($to,$subject,$body,$headers);

#7


2  

if your website domain is mydomain.com then in From headers make sure to use someone@mydomain.com

如果您的网站域名是mydomain.com,那么在From头文件中请确保使用someone@mydomain.com

#8


2  

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.

但是如果你在内容部分之前指定“发件人:”它就像普通邮件一样,让你微笑和好奇。

#9


1  

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.

正如schnalle所说,一个问题肯定是你用来发送电子邮件的smtp服务器和你指定为From的那个服务器是不同的...来自域的域应该与你运行的服务器相同。

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.

因此,您可以使用yahoo服务器发送电子邮件(检查是否允许smtp远程连接,但我猜他们这样做)通过smtp连接,这将解决1个问题。

Another one is the html contents without the alternative plain text contents, but, this one is less important.

另一个是没有替代纯文本内容的html内容,但是,这个内容不太重要。

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)

我建议你phpMailer,免费和开源php类发送电子邮件,轻松使用(我用它事件o通过gmail服务器发送邮件)

#10


1  

  1. On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
  2. 在您的服务器上尝试将SPF(发件人策略框架,Google for SPF记录)记录排序。

  3. Make sure you send your e-mails from an existing account on your server/domain.
  4. 确保从服务器/域上的现有帐户发送电子邮件。

  5. Make sure you have the reply-to address in your header.
  6. 确保标题中有回复地址。

These are the basic things you can try.

这些是您可以尝试的基本内容。

#11


1  

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.

删除Content-type:text / html并添加$ headers。=“X-Priority:2 \ nX-MSmail-Priority:high”;摆脱垃圾邮件。已经尝试并测试了该方法。

#12


0  

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?

问题是,你发送邮件的服务器不是雅虎服务器。大多数垃圾邮件过滤器检查它们是否匹配,否则它(并且是 - 或者是)可以轻易伪造发件人。曾经想知道为什么你从bill.gates AT microsoft.com或你自己的邮件地址收到垃圾邮件?

#13


0  

You've got two solutions:

你有两个解决方案:

  • use Yahoo's SMTP using abc@yahoo.com credentials to send mail from abc@yahoo.com;
  • 使用Yahoo的SMTP使用abc@yahoo.com凭据从abc@yahoo.com发送邮件;

  • use other from, with your own domain;
  • 使用其他来自您自己的域名;

#14


0  

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.

您可以尝试我在此处创建的邮件类和测试文件。我测试了这些文件,可以使用不同的邮件名称向我的hotmail和gmail发送电子邮件。电子邮件标记为垃圾邮件的主要原因是因为结构(标题和邮件)未正确完成。在大多数情况下,导致问题的是换行。

I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)

我可以使用它将包含附件的邮件发送到Gmail。但是,附件不适用于hotmail。希望这有助于=)

You can check the files here..

你可以在这里查看文件..