Hi all,
I written code for sending an email using php.
I don't want to go that mail into spam. How can I avoid going that mail into spam?
Hi all,
I written code for sending an email using php.
I don't want to go that mail into spam. How can I avoid going that mail into spam?
Basically you can't. Every server your mail passes through can mark it as spam, as well as the client's e-mail application.
There are offcourse a few best practices to use to avoid most spamfilters:
There are a lot of things you can do to reduce the chances that your email ends up marked as spam. Arguably the most important is to ensure that your mail server has Sender Policy Framework (SPF) records in place.
Wikipedia has a description (http://en.wikipedia.org/wiki/Sender_Policy_Framework), but you can search on SO and elsewhere for instructions on how to set up your SPF records.
If you are really serious about getting the email to recipients without ending up in spam you can consider using a third party SMTP server like sendgrid.com.
(All this assumes you're not sending spam in the first place)
Jeff Atwood recently wrote an article describing a number of methods to try and avoid this.
http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
However, as Konerak says, you can't guarantee anything!!
To summarise:
Something that gets overlooked often: If you are sending mail manually (i.e. with mail()
, not with a framework) and using sendmail, make sure you set the SMTP envelope sender address.
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/plain; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode($from_name) ."?= <$from_address>\r\n"
."X-Mailer: PHP/". phpversion();
mail($to, $subject, $body, $headers, "-f $from_address");
-f
tells sendmail what address to use in the SMTP wrapper; by default it is the real hostname of the machine, while the from address tends to be an alias. Some spam filters get jumpy when the two addresses don't match.
Other, more obvious advice: