php mail() 防止垃圾邮件 How to Avoid Spam Filters with PHP mail() Emails

本文介绍如何通过使用正确的邮件头信息、确保发件域与服务器域一致、设置content-type属性以及检查服务器是否被列入黑名单等四种方法来减少使用PHP mail()发送的邮件被标记为垃圾邮件的可能性。

4 ways to make your PHP mail () Less Spammy Emails

 

1. Use Headers

 

In the simple example above, the name and email address was added as the fourth parameter. Instead, consider using headers to set the From and Reply-To email addresses.

<? 
$headers .= "Reply-To: The Sender <sender@sender.com>\r\n"; 
$headers .= "Return-Path: The Sender <sender@sender.com>\r\n"; 
$headers .= "From: The Sender <senter@sender.com>\r\n"; 
?>

 

But headlines are good for more than just set the details on the sender. Also important to set the content type, priority mail, and more. Here are how some additional headers look.

<? 
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" 
?>

 

Be sure to replace the fourth parameter of the variable $ headers as shown below.

<? 
mail("recipient@recipient.com", "Message", "A simple message.", $headers); 
?>

 

完整版:

ini_set('SMTP','mail.domain.com');  
ini_set('smtp_port',465);  
ini_set('sendmail_from',"Your Name <your@email>");  
 
$from      = "Your Name <your@email>";
$to          = "toemail@gmail.com";  
$subject   = "Test";  
$message = "<h1>Test</h1> i want to send  emails !";  

$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "From: ".$from."\r\n";

$headers .= "Organization: Your Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=utf-8\r\n"; 
$headers .= "X-Priority: 1\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";

mail($to, $subject, $message, $headers); 

 

2. Message sender domain and server domain must match


Spammers send email from a server and the recipient to believe that it came from somewhere else are notorious for. So if you are sending an email to example@example.com, it is a good idea to keep at example.com script.

 

3. Be sure to use the content-type attribute


The content-type attribute allows a sender of the message to say whether or not an email is plain text or HTML, or have attachments. Obviously, the easiest to use the content type is text / plain. You simply add the text as shown in the example simple, and that's it. However, when using content types, additional parts you would expect. For example, with the content type text / html, HTML body tag is expected. Not having this label may result in an email being marked as spam.

 

4. Verify that your server is not blacklisted


When a server is blacklisted, which means that the server has been identified as one who has been sending a lot of spam. This results in the recipient's mail servers reject or filter all mail that is received from that server. So if your mail is received is not a good idea to check that the server has been blacklisted. This goes for both shared and dedicated servers. In a shared environment, it is common for other users on the server to send spam. And in a dedicated environment, spammers may have found a way to exploit a vulnerability in a server or a contact form to send spam. Making it easy for any type of server blacklisted.

Well, now that you have the basics on how to avoid spam filters, rebuild scripts and email happy!

 

from:  http://blog.infotwistsolutions.com/2013/02/how-to-avoid-spam-filters-with-php-mail.html

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值