-1

Problem is simple. Whenever I try to send an email from my PHP server to a hotmail address it doesnt even reach the hotmail INBOX and neither its SPAM folder.

I am using a custom function for emailing, but I guess that some of the headers are probably incorrect, or maybe they should be in a certain order?

function send_mail($from,$to,$subject,$body){
    global $sitename;
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: $to' . "\r\n";
    $headers .= 'From: $sitename <$from>' . "\r\n";
    $headers .= 'Cc: $from' . "\r\n";
    $headers .= 'Bcc: $from' . "\r\n";

    $headers .= 'Reply-To: $from' . "\r\n";
    $headers .= "Return-Path: $from\n";
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "Date: " . date('r', time()) . "\n";
    if (mail($to,$subject,$body,$headers)) {return TRUE;} else {return FALSE;}
}

I checked the server to see if it's blacklisted. It's not.

What could be the problem? Or maybe someone has a tested PHP mail function that worked with hotmail?

Thanks

NVG
  • 3,248
  • 10
  • 40
  • 60
  • You cannot echo a boolean. – NVG Feb 21 '15 at 11:38
  • For testing you shall `if (mail($to,$subject,$body,$headers)) {echo 'sent';} else {echo 'not sent';}` – Sulthan Allaudeen Feb 21 '15 at 11:49
  • 1
    The problem is not SENDING the email, it is that HOTMAIL accounts do not receive it. GMAIL accounts receive it, so doing what you said is useless. Code works, it doesnt matter if I echo it or not. If you can read what I just said above and have a solution I am waiting for it, but don't waste words without thinking – NVG Feb 21 '15 at 11:53
  • 1
    Ah, sorry then I guess your problem is related to this one http://serverfault.com/a/452896/272621 i.e., `safe senders` – Sulthan Allaudeen Feb 21 '15 at 11:59
  • Probably hotmail is rejecting your email because it doesn't trust the sender. 1. Do you own the domain of the 'from' email? 2. Do you configure SPF or DKIM to add your server as a trusted sender? – artberri Feb 22 '15 at 20:56
  • 2
    See [How to format an email that Hotmail / Outlook is happy with?](http://stackoverflow.com/a/22511714/1237411) – Jasper N. Brouwer Feb 22 '15 at 22:57
  • Also, check the log of the MTA you are using. – Jasper N. Brouwer Feb 22 '15 at 22:58
  • As VaMoose answered SPF is required . check this link for further details :http://help.directadmin.com/item.php?id=207 – Rajesh Feb 24 '15 at 10:47
  • Three thoughts: 1. You have a Bcc field. Why? I'm not sure this will do what you think it will, and it might be a spam indicator from MS's perspective. 2. You end some lines with `\r\n` and others with `\n`. Pick one convention and use it. 3. Don't write your own emailing program. It's a guaranteed headache. 4. (Did I say three?) if you provide a sample (e.g. on a pastebin or gist) of a raw message, we might be able to see other problems that MS is picking on. – Adam Katz Feb 26 '15 at 02:16
  • Does your FROM address receive any bounces from Hotmail at all? They wouldn't just accept the mail and then do nothing with it. They would either reject the mail on connection to their SMTP port or bounce it later. What does your MTA log show? It should show them ACCEPTING the mail, but I bet it shows them saying 'unverified sender' or something like that. – greg_diesel Feb 27 '15 at 23:05
  • Are you sure that the email isn't stuck in your local sendmail program? What does the sendmail log show? – Ja͢ck Feb 28 '15 at 01:59
  • Now the email gets to the recipient, but in JUNK. – NVG Mar 01 '15 at 08:11

4 Answers4

2

Why you don't send via phpmailer? Just create one gmail account or your own email account in your domain.

Example with gmail account:

require("phpmailer/class.phpmailer.php");

function send_mail($fromEmail, $fromName, $subject, $body)
{

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 0; // 1 tells it to display SMTP errors and messages, 0 turns off all errors and messages, 2 prints messages only.
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->Username = "youremail@gmail.com";
    $mail->Password = "yourpassword";
    $mail->From = "youremail@gmail.com";
    $mail->FromName = "yourname";
    $mail->AddAddress($fromEmail, $fromName);
    $mail->AddReplyTo("youremail@gmail.com", "yourname");

    $mail->WordWrap = 50;                                 // set word wrap to 50 characters
    // $mail->AddAttachment("/folder/file.zip");         // add attachments
    $mail->IsHTML(true);                                  // set email format to HTML

    $mail->AddEmbeddedImage('img/logo.png', 'logo'); //if you need a logo signature
    $mail->Subject = $subject;
    $mail->Body    = $body."<br/><br/><a href=\"http://www.yourwebsite.com\"><img src=\"cid:logo\" alt=\"You website title\"></a>";

    // $mail->AltBody = "This is the body in plain text for non-HTML mail clients ;-)";
    $mail->Send();
    if($mail->Send())
    {
        return true;
    }
    else
    {
        return false;
    }

}

More information: http://phpmailer.worxware.com/?pg=examplebgmail

ptCoder
  • 2,229
  • 3
  • 24
  • 38
  • Tried with PHPMailer and the result is the same as when sending it via php mail() ... the email ends in SPAM when sending from some servers, while for others it gets neither in SPAM or INBOX. But this was without SMTP auth. I wanted to be able to continue having a domain email, which is why I left SMTP as a last option. If there is no solution, then I will try SMTP auth using PHPMAILER – NVG Feb 24 '15 at 14:53
  • Check if your mail server blacklisted: http://mxtoolbox.com/blacklists.aspx - enter your domain. It's all ok? – ptCoder Feb 24 '15 at 15:06
  • It's not blacklisted. – NVG Feb 24 '15 at 20:33
  • Please post your code with phpmailer. What is the error? – ptCoder Feb 26 '15 at 10:45
  • Now the email gets to the recipient, but in JUNK. – NVG Mar 01 '15 at 08:12
  • Your email it's gmail? – ptCoder Mar 01 '15 at 15:35
  • Check these topics: http://stackoverflow.com/questions/5943992/phpmailer-php-header-email-goes-to-spam, http://stackoverflow.com/questions/16900641/phpmailer-gmail-spam and http://stackoverflow.com/questions/16717257/phpmailer-mails-going-straight-to-spam – ptCoder Mar 01 '15 at 15:37
1

An SPF record is a type of Domain Name Service (DNS) record that identifies which mail servers are permitted to send email on behalf of your domain.

The purpose of an SPF record is to prevent spammers from sending messages with forged From addresses at your domain. Recipients can refer to the SPF record to determine whether a message purporting to be from your domain comes from an authorized mail server.

If your domain does not have an SPF record, some recipient domains may reject messages from your users because they cannot validate that the messages come from an authorized mail server.

SPF records for outbound gateway

If you decide to enable the email gateway feature, you will need to make sure both Google server's and the outbound gateway SMTP server address is included in the SPF record.

For some more details you can check this link

Rajesh
  • 786
  • 6
  • 12
1

It may happens due to our server which we hosted our php file.

I was also facing same problem. But my problem is occurred due to Dreamhost server. It is black listed from hotmail server.

The solution is I purchased mailjet for send email.

शु-Bham
  • 952
  • 1
  • 7
  • 14
0

Do you have a SPF record? Hotmail blocks domains without a SPF record

you can make one here

VaMoose
  • 196
  • 7
  • Hi. Thanks for the reply, but the service is down since 21st February. – NVG Feb 24 '15 at 14:54
  • SPF record was already added, that's what microsoft is saying, so the problem is not from there either. – NVG Feb 25 '15 at 11:30