We help IT Professionals succeed at work.

PHPmailer and exchange online(Office365)

Hey guys,

I'm having an issue where we've recently upgraded to exchange online(office365) and even tho I updated the PHPmailer info on my Ubuntu server, now my web server will not send email.  I've gone through and checked the necessary settings and configured it using the following Technet article.

in the webapp I'm using the following code.

$mailer = new PHPMailer();
$mailer->SMTPSecure = "tls";
$mailer->Host              = "smtp.office365.com";
$mailer->Port               = "587"; also tested with 25
$mailer->Username    = "Authenticated username";
$mailer->Password     = "password for said authen user";
$mailer->Subject = "subject";

What I'm seeing in the mail.log of my server are 2 errors.  
Valid_hostname: Invalid Character 92 (decimal): \032controlsequipment-com.mail.protection.outlook.com\032
malformed domain name in resource data of MX record for controlsequipment.com: \032controlsequipment-com.mail.protection.outlook.com\032

Based on these messages, I'm assuming the error is due to the dash in the MX record which is a copy and paste from the Exchange online Domain records list.  I've called M$ and they've said that is the proper configuration.

So my question is, how do I get around it with my web app?  I've gone through a bunch of resources on how to configure it but I have the exact same configuration and none of the resources I've gone to mention getting the errors above.   I'm at a loss right now what my next step is.
Watch Question

You're apparently putting in corrupt data to get those error messages, which are nothing to do with PHPMailer; ASCII character 92 is a backslash, so it looks like those `\32` sequences are at fault - validate things before you use them!

Office365 has some issues with SSL, so you may need to disable certificate checking, as described in the troubleshooting docs.

You're setting everything up for SMTP, and then calling `isSendMail()`, which makes no sense as that will make it try to send via a local mail server, bypassing SMTP altogether. Please read the docs and examples provided with PHPMailer - you've based your code on an obsolete example too, so make sure you're using the latest version (5.2.12).


excellent thanks.  I'm not a coder, the application analyst is the one who wrote the app and initially it was an on premise exchange server that that code worked with.  Since we switched to exchange online, it stopped working.  

I'll update PHPmailer to the latest version and go through the documentation to see if I can correct the code.   so the \ is the issue not the dash.  thanks.  I'll report back with an update once I've gone through the provided resource.