Preventing PHP sent mails listed as spam

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spartan7
Forum Commoner
Posts: 29
Joined: Sun Jun 19, 2005 12:09 am

Preventing PHP sent mails listed as spam

Post by spartan7 »

I use the following script to send emails using PHP

mail("$sendto","$subject","$message","From: $name <$email> \nReply-To: $email \nX-Mailer: PHP $phpver", "-f $email");

My emails sent via PHP are always listed as spam (by yahoo etc). How do I prevent this? I've tried to include various headers (X-Sender etc) and it still makes no difference.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it all involves a delicate set of headers, and more and more often now-a-days, the server you are sending from can play a role too.. Compare the headers of emails that don't get into the trash and those that do.. the large a sample pool you have to look at the more you'll be able to figure out faster.. Then work the differences into your script..
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

my PHP sent emails are never listed as spam and a typical snippet I would use/am using now is this:

Code: Select all

$to = "blah@blah.com";
		$subject = "Subject of Blah";

		$from = "From: Blah@Blah.co.uk <whatever@blah.co.uk>\r\n";
		$replyto = "Reply-To: " . $name . " <" . $email . ">";
		$headers = $from . $replyto;

		$message = "Loads of blah...";

		mail($to, $subject, $message, $headers);
so from looking at your post i would suggest removing \nX-Mailer: PHP $phpver from the headers and removing your final parameter (-f $email), i dont even know what it does though :)

HTH
Post Reply