J. Doe
J. Doe

Reputation: 83

How to connect to Office 365 with PHPMailer?

I have a problem with PHPMailer, I want to connect to a Office 365 server which is configured with my website IP, there is made a connector so I can connect to the Office 365 SMTP server to connect without authentication because my IP address is whitelisted.

The problem is that I can not authenticate to the server.

PHPMailer output:

2016-11-23 09:06:50 CLIENT -> SERVER: EHLO www.thuis*******.nl 2016-11-23 09:06:50  SMTP Error: Could not authenticate. 2016-11-23 09:06:50 CLIENT -> SERVER: QUIT 2016-11-23 09:06:50  SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

PHP File:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = '';
$mail->SMTPAutoTLS = false;
$mail->Host = "thuis*******-nl.mail.protection.outlook.com";
$mail->Port = 25;
$mail->SetFrom('john@thuis*******.nl', 'John');
$mail->AddReplyTo("noreply@thuis*******.nl");
$mail->Subject = "This is the subject";
$mail->MsgHTML('Message body');
$address = "[email protected]";
$mail->AddAddress($address);
if(!$mail->Send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
   echo "Message sent!";
}

Upvotes: 0

Views: 1248

Answers (1)

J. Doe
J. Doe

Reputation: 83

Set SMTPAuth to false:

$mail->SMTPAuth = false;

Reason: my server does not have any email accounts configured.

The server IP address is whitelisted to send mail from any mail address with @thuis*******.nl.

Upvotes: 1

Related Questions