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 (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!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


$to = "";
$subject = " Test Subject";
$message = "Test Messsage";
$headers = 'From:' . "\r\n" .
    'Reply-To:' . "\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

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

Dave BaldwinFixer of ProblemsCommented:
This script works to send from my Godaddy account to my Hotmail and Yahoo accounts.  Hotmail did mark it as 'suspicious'.  One of the problems with Hotmail is that it bases it's filtering on the 'reputation' of your email address.  I've had my accounts for many years now and don't have problems anymore.


# some settings of POST vars
if (!isset($_POST['send']))  $send = ''; else $send = $_POST['send'];
if (!isset($_POST['toText'])) $toText = ''; else $toText = $_POST['toText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['subjectText'])) $subjectText = ''; else $subjectText = $_POST['subjectText'];
if (!isset($_POST['msgText'])) $msgText = ''; else $msgText = $_POST['msgText'];
if (!isset($_POST['ccText'])) $ccText = ''; else $ccText = $_POST['ccText'];
if (!isset($_POST['bccText'])) $bccText = ''; else $bccText = $_POST['bccText'];
if (!isset($_POST['nameText'])) $nameText = ''; else $nameText = $_POST['nameText'];
if (!isset($_POST['fromText'])) $fromText = ''; else $fromText = $_POST['fromText'];

if ($send == "") {
    $title="Test Email Page";
else {
	if($fromText === "") die("No name!");
	$title="Test Email Page";
  $announce="Your Message has been Sent!";
	$header = "From: ".$fromText."\r\n";
//	$header .= "Cc: ".$ccText."\n";
	$header .= "Reply-To : ".$fromText."\r\n";
	$header .= "Return-Path : ".$fromText."\r\n";
	$header .= "X-Mailer: PHP\r\n";
	$header .= "MIME-Version: 1.0\r\n";
	$header .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
//	ini_set(sendmail_from,$fromText);  
	mail($toText, $subjectText, $msgText, $header, '-f'.$fromText);
//	ini_restore(sendmail_from);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo($title)?></title>
<style type="text/css">
A:link { color: #999999; }
A:visited { color: #999999; }
A:hover {color: #0099ff;}
<script type="text/javascript">
function check()
var at=document.getElementById("fromText").value.indexOf("@");
var eml=document.getElementById("fromText").value;
var nam=document.getElementById("nameText").value;
var alerttxt="";
var submitOK="true";

if (eml.length < 5 || at == -1)
    alerttxt=alerttxt+"Please enter a valid e-mail address!\r\n";
    //return false;
if (nam.length < 3)
    alerttxt=alerttxt+"Please enter your name.\r\n";
    //return false;
if (submitOK=="false")
    return false;

// -->

<body bgcolor="#ddeedd">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary="" width="580">
<tr><td align="center">

if ($send != "") {
   	echo ("To: ".$toText."<br>\r\nSubject: ".$subjectText."<br>\r\n".$msgText."<br>\r\n".$header);

<p><b><font color="#000000" size="5">Test Email</font></b></p>
<font size="4" color="#000000">

<form method="POST" action="Email.php" onsubmit="return check();">
    <p><font size="3"><b>Name: <input type="text" name="nameText" id="nameText" size="46"></b></font></p>
    <p><font size="3"><b>Email: <input type="text" name="fromText" id="fromText" size="46"></b></font></p>
    <input type="hidden" name="subjectText" value="Web Mail">
    <p><font face="Arial" size="3"><b>Message Text:</b></font></p>
    <p><font face="Arial" size="3"><b><textarea rows="6" name="msgText" cols="60"></textarea></b></font></p>
    <p><font size="3"><b><input type="submit" value="Send" name="send" style="font-family: Arial; font-size: 12pt; font-weight: bold"></b></font></p>
    <input type="hidden" name="state" value="1">
  <b><font face="Arial" size="4" color="#e00000"><?php echo($announce)?></font></b><br><br>



Open in new window

Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Steve BinkCommented:
I've never had problems with mail not getting to Hotmail, though I have seen it marked as spam or suspicious, and usually for a specific reason that I could control.  Here are some suggestions for you:

1) Use a third-party mailer class (like PHPMailer or HTMLMimeMail) to construct the message.  It may just be that you're missing something from the specification that Hotmail does not like.

2) Check your mail logs (if accessible) to find out how Hotmail's servers are responding when the message delivery is attempted.  They may yield some clues.

3) Use proper addressing.  Spoofing "From" addresses, even with legitimate reason, is one of the huge red flags mail providers look for.  Also, make sure your MX and SPF records are configured properly.
dtleahyAuthor Commented:
Thank you all for the suggestions. I'm looking at all these and some other ways...

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

"Validation failed for: "
(the real email account was used in testing, of course)

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

$from = " <>"; 
$to = "Human Being <>";
$subject = "Test Subject Joining";
$body = "Thank you for joining."; 
$host = ""; 
$username = ""; 
$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>");
##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.


Dave BaldwinFixer of ProblemsCommented:
There is no truly "bulletproof" way to send emails.  To improve your chances of getting thru, the email address you are sending from needs to be a recognized address on a mail server that can be looked up and have an SPF record.  We usually recommend checking the status of your mail server here:  

And all the major mail services have pages to help you send to them.

Microsoft Hotmail / Live Mail:


dtleahyAuthor Commented:
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 (

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

Dave BaldwinFixer of ProblemsCommented:
Like I said before, it's not the PHP code but your email addresses reputation that counts with Hotmail.  Most new websites I have set up are unable to send email from a new email address to Hotmail/Live Mail at first.  The big 3 email services are more concerned with blocking spam than with delivering email and Hotmail is the most difficult.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dtleahyAuthor Commented:
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.)


p.s. I could never work on a group project like phpbb. Great forum software, but the code drives me crazy to look at.
dtleahyAuthor Commented:
Thanks very much for the help!
Dave BaldwinFixer of ProblemsCommented:
You're welcome.  The code for things like Wordpress and Joomla drive me nuts also.  And phpMyAdmin.
dtleahyAuthor Commented:
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.

Dave BaldwinFixer of ProblemsCommented:
Good, glad you got it working.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.