I'm trying to set up PHPMailer so that one of our clients can automatically generate emails from their own account. I logged into their Office 365 account and found that the required settings for PHPMailer are:
Host: smtp.off ice365.com Port: 587 Auth: tls
I've applied these settings to PHPMailer, but no email is being sent (the function I'm calling is for our own mail, which is sent from an external server (not the one serving the web page)).
"host" => "smtp.of fice365.com", "port" => 587, "auth" => true, "secure" => "tls", "username" => "clientemail@off ice365.com", "password" => "clientpass", "to" => "myemail", "from" => "clientemail@of fice365.com", "fromname" => "clientname", "subject" => $subject, "body" => $body, "altbody" => $body, "message" => "", "debug" => false
Does anyone know what settings are required to send PHPMailer through smtp.offi ce365.com?
Updated: May 2022
So I'm struggling with this issue. I can provide the answer to this question for enterprise accounts with access to Exchange Online and Microsoft Admin Center.
TLDR: Go to the admin center and select the user you want to send mail to. Then after setting up "Authenticated SMTP" look at the settings after "Email" and "Email Application" and just enable it.
Still not working? I've got you covered, here's how I got it to work completely.
If you use MFA, make sure to use the app password mentioned in https://stackoverflow.com/ a/61359150/14148981
Run script
I hope this helps someone. It took me a long time to find this option.
Get a summary of all steps for app passwords and authentication:
@nitin's code doesn't work for me because it's missing "tls" in the SMTPSecure parameter.
This is a working version. I've also added two commented out lines that you can use if problems arise.