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 <[email protected]>\r\n"; $headers .= "Return-Path: The Sender <[email protected]>\r\n"; $headers .= "From: The Sender <[email protected]>\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("[email protected]", "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 = "[email protected]"; $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 [email protected], 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