Jump to content
kilen

Php Mail() And Hotmail

Recommended Posts

I having some trouble getting emails delivered to Hotmail accounts using the mail() command in PHP. I am receiving email ok on other, paid accounts, but the messages to Hotmail never arrive. Are the headers that automatically get added causing Hotmail to think the messages are spam? I'm starting to question the reliability of using the mail() function, but I'm not sure if using other scripts will fare any better. Any help/advice would be greatly appreciated.

-Troy

Share this post


Link to post
Share on other sites

I've never heard this one...

 

But I'm curious to check it out for myself since many of my members use hotmail.

 

Hmmmm....

 

However, if it turns out that mail() function is a problem (I'd be surprised) then there are alternatives using smtp.

 

More complicated, but much more robust mail.

 

I'll elaborate after I check.

Share this post


Link to post
Share on other sites

I should probably add that this seems to be sporadic. I am able to get it to work tonight to Hotmail, but the reports of failures I have are from other users. And since they may be using Outlook/OE with Junk Mail settings turned on, maybe that is the culprit. Do you have any "how to" resources for using the smtp mail, instead of php mail()? I'd like to learn how it work if you say it is more stable.

 

Thanks,

Troy

Share this post


Link to post
Share on other sites

surefire:

 

just to check with you, when you used PHP's mail() function, did you specify a valid "From:" address in the parameters?

 

My website has a simple RSVP system that I wrote from scratch, and I tested it to send RSVPs to multiple email accounts that I had, one of which was a Hotmail account. At first I too couldn't find the RSVP when I logged in. But then I found that Hotmail has routed it to the "Junk" folder straight away.

 

Adding a valid "From:" address in my scripts cleared up the problem. Now the RSVPs goes to my Hotmail Inbox folder without fail.

Share this post


Link to post
Share on other sites

I just checked it out on a plain jane hotmail account... no problems.

 

I should probably add that this seems to be sporadic. I am able to get it to work tonight to Hotmail,

 

Now you tell me...

 

Just kidding. :)

 

It's not easy... it involves downloading a script, and understanding the basics of object oriented programming in PHP.

 

I'm not trying to be snotty. But have you ever gotten neck deep into something and wished that someone had told you how involved it is... well, it's involved.

 

But let me go find the link for you. Be back in a sec.

 

PS - I didn't really say it was more stable... more robust. Meaning that you can send html and have a little more control over the headers as if the mail was really sent through your TCH email account.

 

I've never had reported problems with the mail() function. So I consider it pretty darn 'stable'.

 

Now for that url...

Share this post


Link to post
Share on other sites

Darkwoof,

No, I didn't specify any from address... and it worked fine. Showed up in my hotmail account as From (blank).

 

So, I don't know what to tell you on that one. I cranked out a test script, set up a hotmail account, and tested it out.

 

No probs...

 

 

 

Here's a link to phpmailer, the script I use

http://phpmailer.sourceforge.net/

 

Hope that helps.

Share this post


Link to post
Share on other sites

Thanks again for all your help. The scripts I am using sometimes specify a valid From address, so that may be the problem. If the user filling out the web form includes their email address (optional), the from field is populated in the headers with their email address. Otherwise, it is blank, which is probably going into the Junk Mail. I think that isolates the problem.

 

If the SMTP alternative is involved, I'll probably continue to just use mail(). I at least can get mail() to work ok, and I'm not up for hours of troubleshooting right now. I'm not that skilled with these things, and sometimes still struggle with some of the PHP basics. At least I know now the importance of specifying a valid From address to avoid being considered Junk Mail.

 

Thanks,

Troy

Share this post


Link to post
Share on other sites

From the user comments on the PHP Manual page for mail():

 

...

I had trouble sending emails with mail()function some peple would get the emails then other would not, I had partialy solved this problem (see my post above) with avoiding mail function. It solved the problem but still for example hotmail would only get 3/10 sometimes 0/10 messages, I have now compleately solved this problem by adding ALL REQIRED headers and changing the sendmail path with envelope matching address ......

 

ini_set(sendmail_path, "/usr/sbin/sendmail -t -f webmaster@domain.com");

 

//Contents of an Registration Auto responce email(text format)

$message = "Thanks for registering".$userName;

 

$headers .= "From: Name<webmaster@domain.com>\n";

$headers .= "Reply-To: <webmaster@domain.com>\n";

$headers .= "X-Sender: <webmaster@domain.com>\n";

$headers .= "X-Mailer: PHP4\n"; //mailer

$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal

$headers .= "Return-Path: <webmaster@domain.com>\n";

mail($email,"Registration COnfirmation",wordwrap(stripslashes($message)),$headers);

//Uncomment this to send html format

//$headers .= "Content-Type: text/html; charset=iso-8859-1\n";

//$headers .= "cc: birthdayarchive@php.net\n"; // CC to

//$headers .= "bcc: mail@server.com"; // BCCs to, separete multiple with commas mail@mail.com, mail2@mail.com

...

 

Lots more lore on the page; here.

Share this post


Link to post
Share on other sites

btrfld,

 

Great post! Useful stuff.

 

I often forget to check the php.net page. They have a ton of good user feedback for how php is being applied in the real world.

 

Now I've got to go back and double check that my hotmail members are getting my emails.

 

Yikes. Lots o' programming. :)

Share this post


Link to post
Share on other sites
Darkwoof,

No, I didn't specify any from address... and it worked fine. Showed up in my hotmail account as From (blank).

 

So, I don't know what to tell you on that one. I cranked out a test script, set up a hotmail account, and tested it out.

 

No probs...

 

 

 

Here's a link to phpmailer, the script I use

http://phpmailer.sourceforge.net/

 

Hope that helps.

Heh... that's strange... may be just my account then. It forwarded every email I sent from my script to the Junk folder even though I didn't set up any spam filtering...

Share this post


Link to post
Share on other sites

Yep. I tried it twice.

 

That doesn't mean that it will work 100% of the time.

Share this post


Link to post
Share on other sites

It is a good policy to always have a valid FROM: address on mails sent by scripts. If you're using input provided from the user as the FROM: address, you should use a routine to check whether one is provided in the valid format, and if not supply one of your own in its place.

Share this post


Link to post
Share on other sites

Darn good suggestion matman

 

Somewhere I even found a PHP script that would somehow check the validity of an email address BEFORE sending out the email. Somehow it could verify the address was 'good' most of the time.

 

But the point is: don't trust user input to be safe or in the format you expected.

Share this post


Link to post
Share on other sites

I am also experiencing PHP mail() problems. I am using a valid "From:" header, but sometimes, the mail just won't send. The very first time I tried it to my Yahoo account, the mail took over a day to get there, but now it gets there lickity-split. Yesterday, I tried to send email to another account (not yahoo, my dad's work) and some of the emails didn't get sent -- the ones that did took about an hour to get there.

 

How exactly does the mail() command work through tch (is there a website to read how it works?)

Share this post


Link to post
Share on other sites

Although this isn't a simple fix... it's super effective:

 

Here's a link to phpmailer, the script I use

http://phpmailer.sourceforge.net/

 

Follow the directions and it's pretty straightforward.

 

My personal experience is that sending mail using SMTP option is MUCH faster. I'm in the process of replacing all of my mail() functions with this mail class script.

Share this post


Link to post
Share on other sites

Did we ever get to a conclusion about why some email addresses do not accept the emails from the PHP mail() function?

 

I am currently having this problem and ripping my hair out trying to find out between like 3 different places why the emails are not being sent through.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...