phpemailhotmail

Why can't I send an email to Hotmail?


Here's my code:

$boundary = sha1('whatever');

$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'From: "Domainname" emailname@domain.com'."\r\n";
$headers .= 'Reply-to: Domainname <emailname@domain.com>'."\r\n";
$headers .= 'X-Priority: 3'."\r\n";
$headers .= 'X-Mailer: Mail 1.0'."\r\n";
$headers .= 'Subject: '.$subject."\r\n"; 
$headers .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"'."\r\n\r\n";

$message = '--'.$boundary."\r\n";
$message .= 'Content-Type: text/plain; charset="utf-8"'."\r\n\r\n";
$message .= $text."\r\n";
$message .= '--'.$boundary."\r\n";
$message .= 'Content-Type: text/html; charset="utf-8"'."\r\n\r\n";
$message .= $html."\r\n";
$message .= '--'.$boundary.'--';

mail($email, $subject, $message, $headers);

It worked for Gmail, Yahoo, GMX ...but it didn't work for Hotmail/Live/MSN.

Because it worked for Gmail, I can assume that it has nothing to do with my server, right?

I also tried it with just:

mail('username@hotmail.com', 'This is a subject', 'This is the body');

Same problem. It doesn't even get send to my junk folder.


Solution

  • Old answer:

    Hotmail blocks domains without an SPF record. you can make one here

    edit:

    As of June 2015, common requirements are:

    1) DKIM Enabling DKIM in Exim is now a very important tool to reduce the chance of your emails being flagged as spam. It's highly recommended to enable DKIM for your domains.

    2) SPF record with -all instead of ~all

    3) DMARC records to help remote servers decide what to do with failed DKIM/SPF messages.

    4) The usual things, a) like reverse IP lookup on sending IP, b) forward lookup on that rDNS value preferably pointing to same IP, c) MX record on hostname.

    Example:

    "v=spf1 a mx ip4:1.2.3.4 -all"
    

    Where 1.2.3.4 is the ip of your server.