tags:

views:

663

answers:

5

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?

+10  A: 

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:

  • Put a nice 'From' line. Don't include www. or http or anything website-related that might cause filters to think it's spam.
  • Avoid spammy-keywords (free/viagra/penis/...)
  • Put a clear subject so even if it gets in the spam-folder, viewers will see they asked for it (Your registration details for the Thingy-Thingy Website)
  • After the user registers on your site, do mention he needs to check his spam/junk folder as well!
  • Make sure your SMTP server has a decent reputation (implements SPF, not blacklisted)
Konerak
A: 

Do not send spam?

lfx
Hello captain obvious
Robus
@Ifx this is not about how to send spam, but how to prevent automatically sent (legitimate) E-Mails from ending up in the spam folder, which happens quite often.
Pekka
A: 

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)

Greg
+7  A: 

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:

  • Reverse DNS
  • DomainKeys Identified Mail
  • SenderID
Robin Day
Thanks, nice link.
Konerak
There's no downvote on this now. Might have been a misclick at the time you saw it? :) (Sweet link, by the way!)
pinkgothic
+1  A: 

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:

  • make sure the from/reply to address resolves to the machine you are actually sending from
  • make sure no spam gets sent from your machine (open relay, other users, a website where you can enter any email address without confirmation)
  • don't use techniques which are used by spammers to trick filters (e.g. text as image)
Tgr
+1, Proper headers in my experience were the most useful to get the message through spam traps. Too many bots and forms don't send any nowadays..
Nullw0rm