开发者

php mail() -> junk, sometimes not even received?

I am using phps mail() function to send confirmation e-mails.

The e-mails get received on gmail and others as far as I'm aware, the only real problems I've had is when sending the e-mails to a Hotmail or Yahoo accoun开发者_如何学Pythont.

I have read on the internet and many people suggest PHPmailer

What do you guys suggest to do when sending php mail()? This website I'm creating is for a legitimate business and I need mail to be sent and received no matter whom I send it to.

Below is my code currently, I've used specific headers to try solve the problems. I own my own dedicated server and I'm not blacklisted on any spam lists, all I can think of is it is php itself.

$to = $email;
$subject = "Subject";
$body = "Message";
$headers .= "From: Accounts <accounts@site.com>\r\n";
$headers .= "Reply-To: <accounts@site.com>\r\n";
$headers .= "X-Sender: <accounts@site.com>\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . '\r\n'; //mailer
$headers .= "X-Priority: 3\r\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <accounts@site.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n"; 
mail($to, $subject, $body, $headers);

Any help is greatly appreciated.

Regards.


Using PHPMailer, or swiftmailer or any other library won't increase your delivery rates in most cases: the most likely culprit is your server set up.

Sending email successfully is notoriously difficult, have a read here: http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html for a basic overview of what's necessary.

Yahoo in particular really wants DKIM set up, and if your ISP hasn't done this for you, or you are on a VPS, can be a real pain.

Sucessfully sending email takes quite a bit more then simply not being on blacklists. The default of many ISPs it so assume you are SPAM until you have things set up that would make them think otherwise. Guilty until proven innocent.

In the codinghorror post, take note of this passage:

Port25 offers a really nifty public service -- you can send email to check-auth@verifier.port25.com and it will reply to the from: address with an extensive diagnostic!

I had to use an alternate address for the test to work; check-auth2@verifier.port25.com. You can read the details of why to test with each address here: http://www.port25.com/domainkeys/

In the long run, if you're sending transactional email (ie. not mass mailings but email in response to a user action) I recommend a service like postmark (postmarkapp.com) because at 1/10th of a cent per email, you get all the ugly taken care of for you.


php mail() function is not a perfect thing to use. Many a times, google/yahoo or some other email providers block the addresses of your hosting, as a result the mail never reached in the destination (so, not in the junk box also). Sometimes, you might face that you sent to two email addresses in different domain (say, gmail and hotmail), one got delivered, other not. So mail() function, though is very simple and easy to use, not suitable always if you want reliable email delivery.

To me, best thing is to use smtp server of your hosting or any gmail address if your hosting support FSOCKOPEN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜