php mailer not delivering emails to hotmail.com account

Hi guys, I’m having a very strange problem here. I have a contact form and upon submission it’s supposed to send an email to a specific email address, (it’s a hotmail.com if that’s important). The form submits OK but I don’t receive any email, not even on the junk folder: no errors anywhere. To make sure that I wasn’t making any silly errors in the code, I redirected the form submission to another email address, a hotmail.co.uk, and lo and behold, I do receive an email. Needless to say, I had a good look online, and, although I’m a php beginner it seems that my code doesn’t have any major issue (as I said it works with another email address). I’m a bit confused, and not sure how to resolve that. So, let’s have a quick look at the code (the password has been replaced of course):

[php]

<?php require 'PHPMailer-master/PHPMailerAutoload.php'; //header('Content-Type: application/json'); //SMTP needs accurate times, and the PHP time zone MUST be set //This should be done in your php.ini, but this is how to do it if you don't have access to that date_default_timezone_set('Etc/UTC'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $firstName = filter_input(INPUT_POST, 'firstName', FILTER_SANITIZE_STRING); $lastName = filter_input(INPUT_POST, 'lastName', FILTER_SANITIZE_STRING); $emailAddress = filter_input(INPUT_POST, 'emailAddress', FILTER_SANITIZE_EMAIL); $message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING); $website = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_URL); $mail = new PHPMailer(true); $mail->Timeout = 30; // set the timeout (seconds) //$mail->isSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "tls"; // sets the prefix to the servier $mail->Host = "smtp.live.com"; // sets hotmail as the SMTP server $mail->Port = 587; // set the SMTP port for the hotmail server $mail->Username = "[email protected]"; // hotmail username $mail->Password = "xxxxxxxxxx"; // hotmail password //$mail->setFrom($emailAddress, $firstName . ' ' . $lastName); $mail->setFrom("[email protected]", "No reply"); $mail->addAddress('[email protected]', 'Rosie'); $mail->Subject = 'New myfavourbox request'; //$mail->Body = $message . "\r\n\r\nWebsite: " . $website; $mail->Body = "First Name: " .$firstName . "\r\n\r\nLast Name: " . $lastName . "\r\n\r\nEmail address: " .$emailAddress . "\r\n\r\nMessage: " . $message . "\r\n\r\nWebsite: " . $website; if(!$mail->send()){ echo "Mailer Error: " . $mail->ErrorInfo; http_response_code(400); } else{ echo "success"; } } ?>

[/php]

As mentioned before, if I change the email address (and password of course) in the file from [email protected] to [email protected], I receive the email (even though in the junk email, but let’s leave this last problem for later).
Does anybody have any suggestion? For completeness, here is the website in question, it may or may not be useful, I don’t know:http://antonioborrillo.co.uk/rosie/en/index.php.
Also it’s worth noticing that the form is submitted via ajax, but again, that works, it’s just the email that doesn’t come through. Any help from you guys is much appreciated.
thanks

add authentication to your server, dkim spf records. Hotmail is really good at blocking mail, but that is a start.

Also, due to the DMARC protection in AOL, Yahoo, Gmail and Hotmail, you can not set the FROM address to
your own address. The FROM MUST be set to an address on your server. Then, set your REPLY-TO to your
own address so you get replies… I had a lot of trouble with this until I learned about DMARC…

Google it if this doesn’t work for you…

The following might help you out in testing locally and remotely without having to commenting out?
[php] if (filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL) == “localhost”) {
$mail->isSmtp(); // Local Host:
$mail->Port = EMAIL_PORT; // Local Host Port: (Usually 587)
} else {
$mail->isSendMail(); // Remote Host:
}[/php]

Guys,
thanks for all the suggestions. Now, please bear with me as I’m a php novice so many things still makes no sense to me at all, and also I’m not so knowledgeable as far as server config is concerned, I’ve done all this only twice and luckily for me it worked straightaway. I’ll try to address all the suggestions:
1)[member=72272]astonecipher[/member]: do I have to talk to the hosting provider for that? Not sure how much access I have to the server, perhaps I’ll ask them to do it?
2)[member=43746]ErnieAlex[/member]: I didn’t know that.

The FROM MUST be set to an address on your server
OK but which address from the server? DO you mean that I have to create another email address and use that for the FROM? Can I use a non-existent one or do I have to actually create one (sorry that sounds like a dumb question)? About the reply-to, I’ve done a bit of googling around and this seems to be what I need: [php]$mail->AddReplyTo(‘[email protected]’, ‘Rosie’);[/php]. I’ve also looked into this DMARC policy thingy, briefly, and I’ve essentially found what you’ve just said, that because of that the FROM address can’t be the same as your address, but there is not mention of hotmail, only yahoo apparently
[member=57087]Strider64[/member]: does that snippet need to be added to the code as it is? worth mentioning that everytime I used [php]$mail->isSmtp(); // Local Host:[/php] both in this project and in the previous ones, phpmailer couldn’t send the email

One more thing guys,I’ve been playing around with the php file, and apparently just by removing the same address from setFrom resolves the issue in the sense that now I receive the email. But rather than replacing it with another email, I’ve replaced it with the email address entered by the user. I’ve also added the reply-to functionality which replies to the user email and finally added the CC functionality. All this works but, it creates 2 more issues:
if thesetFrom address is set to the address the user typed in when they submit the form, it is very likely that most of the submissions will end up in the junk folder. This probably ties in with what [member=43746]ErnieAlex[/member] said, which is to use a server email address - presumably I need to create another address just for using it on the setFrom?
This AddCC got me thinking: as CC address I used the email address the user typed in, so that when the form is submitted, he/she will receive a copy of the submission. Does it sound OK?
Anyway, here is the modified code, just for reference:
[php]
$mail = new PHPMailer(true);
$mail->Timeout = 30; // set the timeout (seconds)
//$mail->isSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = “tls”; // sets the prefix to the servier
$mail->Host = “smtp.live.com”; // sets hotmail as the SMTP server
$mail->Port = 587; // set the SMTP port for the hotmail server
$mail->Username = "[email protected]"; // hotmail username
$mail->Password = “xxxxxxxxxx”; // hotmail password
$mail->AddReplyTo($emailAddress, $firstName);
$mail->setFrom($emailAddress, $firstName . ’ ’ . $lastName);
$mail->addAddress(‘[email protected]’, ‘Rosie’);
$mail->Subject = ‘New myfavourbox request’;
$mail->AddCC($emailAddress, $firstName);
$mail->Body = "A new myfavourbox request has been submitted.\n\nFirst Name: " .$firstName . "\r\n\r\nLast Name: " . $lastName . "\r\n\r\nEmail address: " .$emailAddress . "\r\n\r\nMessage: " . $message . "\r\n\r\nNumber: " . $number;

[/php]

Well this is a subject I know all too much about (at least if I can remember it all since the time I setup my server anyway). Any of the microsoft email domains are very difficult to hit people’s inboxes even with the best php and server setups until your server has a “good reputation” for sending non-spam email. I have a great article http://amecms.com/article/Sending-email-in-PHP-and-reaching-the-inbox that goes into detail about how to do many of the things that have been suggested to you. Granted most of those things can only be done if you are on a dedicated server and not a typical shared host server.

Even after doing everything 100% correct on my own dedicated server I still found it almost impossible to hit a hotmail inbox. So what I did was create a brand new Gmail account and then using smtp I send any email going to a microsoft account through the gmail server. Because gmail has a very high reputation, my emails have reached the inbox virtually every time. I use a simple if() to check the domain of the email address and then send it to gmail if needed.

Jazzo,
If your email that you are sending to is on your server, yes, the FROM can be your email address.

If your email that you are sending to is [email protected] and your server is jazzo.com, it will not work.
( In this case, you need to make a junk email account on your jazzo.com’s server. I use [email protected].
And, then, set the FROM to the info[member=76422]jazzo[/member].com and set the REPLY-TO to your [email protected]. In this
way, DMARC is satisfied and when the recipient replies to your email they send it to your own account. )

Try it and let us know… (I had this on a Godaddy server that I have and it fixed it nicely!)

Thanks guys, touch wood, everything seems to be working OK. I had a look at your article [member=57551]fastsol[/member], it’s rather interesting, but it seems like it’s now working with an hotmail.com account.
[member=43746]ErnieAlex[/member]: OK understood, thanks for explaining. Currently I’m sending from a different server, and even when the site will go live it will be from a different server anyway, so I will be creating an email account from the new domain and send it from there. Hopefully, this will solve the junk email issue, because with the settings I have now, the FROM is different all the time and I reckon that’s one of the reasons the emails always end up in the junk folder. If I change the FROM to a [email protected] it will be a fixed address so once I label the email from that address as not junk, it should work. I’ll have a go and see what happens!
Will post back once I’ve tried, probably this weeken
thanks!

One key thing to understand, when you are sending test emails to an account you cannot open those test emails at all. Once you open the test email you taint the delivery stats from that point forward. The email domain (hotmail, outlook, etc) monitor what you do with every email that is sent to your account. If you open an email and don’t mark it as spam or don’t delete it, they consider that as a slight positive note towards possibly delivering it to your inbox the next time.

Are these emails that you are sending from your site ONLY meant to go to an admin of your website, or are emails being sent from your website to normal visitors? If all emails are only going to one person, then simply add the email address to your safe contact list in hotmail. Otherwise you must test on multiple email accounts to where you never open the test emails to ensure they are being consistently delivered to the inboxes.

If you aren’t using a dedicated server with a private ip where you can setup the proper dns entries, you are basically relying on the reputation of the server and shared ip that you are using to ensure delivery. For some people that may be fine, but you have to understand that your ability to deliver could change in an instant all due to another website on your shared ip that has become blacklisted. You can certainly run it how ever you want, I’m just trying to make sure you understand that without certain things in place, all your testing could mean nothing in the end.

When I said sent through SMTP, I did not mean your host companies SMTP. For instance, you have a gmail account. That gmail account has credentials. Those credentials can be used to log into googles’ smtp and send mail, from that address. If done properly it cuts out a lot of the headaches. There are other ways/ systems, but this will be the easiest for you now.

thanks guys. The email will be sent to the owner of the site and to the user who submitted the form - as a summary of the enquiry. I resolved it anyway by using the address which matches the domain, that seems the best solution to me.

Sponsor our Newsletter | Privacy Policy | Terms of Service