Link to home
Start Free TrialLog in
Avatar of dtleahy
dtleahyFlag for United States of America

asked on

php mail() function not working to send to Hotmail

I have a php script that will successfully send email to other email servers, but not to Hotmail. It doesn't even trap it as spam - just does not receive it.

In my reading, I found reference to the fact that Hotmail will not receive a message generated by the php mail() function. I find that impossible to believe, but it shows others are seeing a problem (and what are the odds they are trying from the same hosting company.)

I think it might be a problem with headers - header references to the sender's email address not being identical.

My website is hosted at WebHostingHub.com (maybe they are blacklisted at Hotmail?)

Supposedly (and this makes sense), the spam filters look for messages that obviously appear spoofed. The way WebHostingHub sends out email, it is using my main email account, and I can't change that behavior - and don't want to use that (admin) email address at all in the headers. I did create another email account, and put that in the "from" and "reply-to" headers, but from the mailserver logs the hosting company tech was reading, I think it still has the main/admin email account listed in the path (even though I have the "from" email address that I want, listed in the visible header.)

Any help on this will be greatly appreciated!

Dennis
Avatar of dtleahy
dtleahy
Flag of United States of America image

ASKER

Here is very simplified code, that will not get a message sent to my Hotmail account:

<?php

$to = "aRealEmailAddress@hotmail.com";
$subject = " Test Subject";
$message = "Test Messsage";
$headers = 'From: activation@ResetButton2012.org' . "\r\n" .
    'Reply-To: activation@ResetButton2012.org' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


 if (mail($to, $subject, $message, $headers)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }
  
?>

Open in new window

Avatar of dtleahy

ASKER

Update:
I am looking into PEAR right now - perhaps to circumvent the problem instead of beating my head against the wall.

Dennis
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtleahy

ASKER

Thank you all for the suggestions. I'm looking at all these and some other ways...

Dennis
Avatar of dtleahy

ASKER

(The way I have it set up) PEAR does not work.

Error:
"Validation failed for: activation@mydomain.org "
(the real email account was used in testing, of course)

(here is the code I tried, but all data was real when I tried)
<?php
require_once "Mail.php";

$from = "activation@mydomain.org <activation@mydomain.org>"; 
$to = "Human Being <real@thedomain.com>";
$subject = "Test Subject Joining";
$body = "Thank you for joining."; 
$host = "mail.mydomain.org"; 
$username = "activation@mydomain.org"; 
$password = "EmailAccountPW"; 
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);  		
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username,'password' => $password));
 
$mail = $smtp->send($to, $headers, $body);
 
if (PEAR::isError($mail)) {
	echo("<p>" . $mail->getMessage() . "</p>");
	} 
else 
	{   					
##Send activation Email:
	echo "An email has been sent to ".$to." with an activation key. Please check your mail to complete the authentication.";		
	}
					
?>

Open in new window


A support person at my web hosting provider said that he sees the messages in the email server log files, so the account and password are are good. But the support person says he also sees that they are not being successfully sent. Something is still missing, or not set up properly...

...can anyone help me either figure this out quickly, or recommend a "bulletproof" way to send emails programatically that will get through. This is not advertising or spam -these are validation/activation emails, and obviously it is critical that the email goes through every time.

Thanks!

Dennis
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtleahy

ASKER

Great answer, Dave. Obviously, not the one I wanted to hear, but a bucket of cold water in the face is usually wiser than a carrot on a stick. :~)

If it was not so damn hard for a php beginner to read the open source code that phpbb forum uses, I would dive in there and find out what they use. Generally speaking (having set up several forums using the free phpbb forum application), the activation emails always, always go through. That is written in php.

I did dig through a lot of the Microsoft troubleshooting, but as is typical with those guys, you need a day and a half to dedicate to all the myriad possibilities. Nothing leaps out at me, but then, I'm too "green" in this programmatic mail functionality to see the forest or the trees. Ya gotta love this form from the boys and girls in Redmond (https://support.msn.com/eform.aspx?productKey=edfsmsbl&ct=eformts&wa=wsignin1.0&st=1&wfxredirect=1)

I think I am going to dig through the phpbb code...

Dennis
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtleahy

ASKER

Good thinkin', Dave. (about sending out mail, priming the pump) I did hear what you were saying about reputation being a factor, bit I'll treat it as the main factor.

I suppose I'll have to create a few gmail accounts and Yahoo accounts too. (I have a Hotmail and a Live.)

Dennis

p.s. I could never work on a group project like phpbb. Great forum software, but the code drives me crazy to look at.
Avatar of dtleahy

ASKER

Thanks very much for the help!
You're welcome.  The code for things like Wordpress and Joomla drive me nuts also.  And phpMyAdmin.
Avatar of dtleahy

ASKER

DaveBaldwin said:
Since you have a Hotmail account, send some emails from that account to the account you're trying to use so at least Hotmail has some record of it being an acceptable email address.

Just thought I'd mention that after just a few successful emails sent from my new domain to my Hotmail account, now programmatic emails from my domain are going through to Hotmail.

So, it didn't take nearly as long as expected. Thanks again, Dave.

Dennis
Good, glad you got it working.