Remember HEADERS when sending mail from a site.

by Dave on January 19th, 2009

Generally speaking, the e-mail will go to junk because of incomplete and missing headers. Many spam filters pick these “lack of headers” as a commonality between all those e-mails for all those enlargement pills and pirated software we’ve all been after.

Your mail code is slightly incorrect though, generally speaking the usage for mail is:

mail(“To”,”Subject”,”Message”,”Headers”)

Which could explain why it went to junk the first time. Therefore you would have something like this established:

$headers = “MIME-Version: 1.0\r\n”;
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”; // Important to change if you ever add attachments
$headers .= “From: “.$email_address.”\r\n”;
$headers .= “Reply-To: “.$email_address.”\r\n”;
$headers .= “X-Mailer: PHP/”.phpversion().”\r\n”;

I’m sure you can work out the rest. Word of warning though, your e-mail address may be blacklisted as “junk” if you didn’t set the “from” value. There are many more headers that you may want to look up RFC2821 or some explanation on various headers.

From → PHP, Web Development

No comments yet

Leave a Reply

You must be logged in to post a comment.