I have been using PHPMailer to send SMTP email on behalf of my office365 account, and it was working for about a week. Then it suddenly quit working and I don't know what changed.
When I enable high debug logging in PHPMailer I see this:
SMTP -> FROM SERVER:220 CY4PR15CA0011.outlook.office365.com Microsoft
ESMTP MAIL Service ready at Thu, 10 Jan 2019 13:30:20 +0000 SMTP ->
FROM SERVER: 250-CY4PR15CA0011.outlook.office365.com Hello
[198.154.243.158] 250-SIZE 157286400 250-PIPELINING 250-DSN
250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME
250-CHUNKING 250 SMTPUTF8 SMTP -> ERROR: AUTH not accepted from
server: 504 5.7.4 Unrecognized authentication type
[CY4PR15CA0011.namprd15.prod.outlook.com] SMTP -> FROM SERVER:250
2.0.0 Resetting
This piece seems to be the most relevant:
AUTH not accepted from server: 504 5.7.4 Unrecognized authentication
type
Here are my literal SMTP settings as being handed to PHPMailer:
smtpAuth: true
smtpSecure: STARTTLS
smtpHost: smtp.office365.com
smtpPort: 587
smtpUsername: [hidden]
smtpPassword: [hidden]
emailTo: [hidden]
And the actual PHP code:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = $smtpAuth;
$mail->SMTPSecure = $smtpSecure;
$mail->Host = $smtpHost;
$mail->Port = $smtpPort;
$mail->Username = $smtpUsername;
$mail->Password = $smtpPassword;
$mail->SetFrom($smtpSenderDisplay);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($emailTo);
As as sanity check, I set up an SMTP account with these same settings in Windows Live Mail - and everything works. No errors. Outgoing email lands in the inbox of a different email account I have.
So Windows Live Mail is doing something a little differently from what my PHP script is doing AND remember my PHP script was working fine up until a few days ago.
Any ideas what I need to change?
Microsoft changed their SMTP encryption requirement from STARTTLS to TLS. That solved it.
Related
I'm using code below to send mail but I get Authentication unsuccessful. The same code works with smtp.gmail.com, but not with smtp.office365.com.
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//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');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 4;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'tls://smtp.office365.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "anonymized#anonymized.com.br";
//Password to use for SMTP authentication
$mail->Password = "anonymized";
//Set who the message is to be sent from
$mail->setFrom('anonymized#anonymized.com.br', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('anonymized#anonymized.com.br', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('anonymized#anonymized.com.br', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I get the following output:
2017-06-06 18:24:34 SERVER -> CLIENT: 220 FR1PR80CA0087.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 6 Jun 2017 18:24:25 +0000
2017-06-06 18:24:34 CLIENT -> SERVER: EHLO desenv
2017-06-06 18:24:34 SERVER -> CLIENT: 250-FR1PR80CA0087.outlook.office365.com Hello [201.47.213.100]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 CHUNKING
2017-06-06 18:24:34 CLIENT -> SERVER: STARTTLS
2017-06-06 18:24:34 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2017-06-06 18:24:35 CLIENT -> SERVER: EHLO desenv
2017-06-06 18:24:35 SERVER -> CLIENT: 250-FR1PR80CA0087.outlook.office365.com Hello [201.47.213.100]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN250-8BITMIME250-BINARYMIME250 CHUNKING
2017-06-06 18:24:35 CLIENT -> SERVER: AUTH LOGIN
2017-06-06 18:24:35 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-06-06 18:24:35 CLIENT -> SERVER: xxx
2017-06-06 18:24:35 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-06-06 18:24:35 CLIENT -> SERVER: xxx
2017-06-06 18:24:40 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [FR1PR80CA0087.lamprd80.prod.outlook.com]
2017-06-06 18:24:40 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [FR1PR80CA0087.lamprd80.prod.outlook.com]
SMTP Error: Could not authenticate.
2017-06-06 18:24:40 CLIENT -> SERVER: QUIT
2017-06-06 18:24:40 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I tried many things. Changing file encoding because in this question smtplib.SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful') the problem was the encoding of the password.
I tried using this, as in PHPMailer Authentication unsuccessful:
$mail->SMTPAuth = False;
But I got:
2017-06-06 18:28:59 SERVER -> CLIENT: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM]
2017-06-06 18:28:59 SMTP ERROR: MAIL FROM command failed: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM]
The following From address failed: rrjuridico#grupopetropolis.com.br : MAIL FROM command failed,5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM],530,SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 530
Mailer Error: The following From address failed: rrjuridico#grupopetropolis.com.br : MAIL FROM command failed,5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] ,530,SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 530SMTP server error: MAIL FROM command failed Detail: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [RO1P215CA0017.LAMP215.PROD.OUTLOOK.COM] SMTP code: 5302017-06-06 18:28:59 CLIENT -> SERVER: QUIT
2017-06-06 18:28:59 SERVER -> CLIENT:
2017-06-06 18:28:59 SMTP ERROR: QUIT command failed:
I tried removing line below:
$mail->isSMTP();
I got Message sent!, but email wasn't sent.
Any Idea, any help would be very much apreciated.
It just looks like you have the wrong ID and password. They were easily decoded from the SMTP transcript (I have removed them - you might want to change your PW now), but your password only contained ASCII characters, so it's not an encoding problem.
You do need to authenticate in order to send on most systems, so your second example makes sense.
Not calling isSMTP() means that it defaults to using mail(), which relays your message via a local mail server; the local delivery may succeed, but the onward delivery many still fail - this matches what you're seeing. To check that, look in your mail server log (usually /var/log/mail.log or nearby).
I'm new to PHP and trying to build a website with registration form. Users should receive an email with a confirmation link (since I have a free hosting server I am trying to use gmail server). The thing is I'm struggling with the email php code. I am trying to use PHPMailer functions as follows:
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//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');
require 'PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "MYEMAIL#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "MYPASSWORD";
//Set who the message is to be sent from
$mail->setFrom('example#example.com', 'Name S');
//Set an alternative reply-to address
$mail->addReplyTo('example#example.com', 'Name S');
//Set who the message is to be sent to
$mail->addAddress('email#gmail.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("HELLo");
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I tried both ports 587 and 465. Also tried both ssl and tls. Every time I try to run the code I get the following error:
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP gw4sm17090153wjc.45 - gsmtp
CLIENT -> SERVER: EHLO spec.dr-manny.co.uk SERVER -> CLIENT:
250-smtp.gmail.com at your service, [185.27.134.36]250-SIZE
35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN
OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 CLIENT -> SERVER: AUTH LOGIN SERVER -> CLIENT: 334
VXNlcm5hbWU6 CLIENT -> SERVER: bWFubnlzYWVkaUBnbWFpbC5jb20= SERVER ->
CLIENT: 334 UGFzc3dvcmQ6 CLIENT -> SERVER: a2luZ29uZW1vaDk5 SERVER ->
CLIENT: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP ERROR: Password command failed: 534-5.7.14
Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 gw4sm17090153wjc.45 -
gsmtp SMTP Error: Could not authenticate. CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection gw4sm17090153wjc.45 -
gsmtp SMTP connect() failed.
Error: SMTP connect() failed.
Also, I got an email from Gmail with the subject "Someone has your password". I opened the email and found this "
Hi Manny,
Someone just used your password to try to sign in to your Google Account MYEMAIL#gmail.com, using an application such as an email client or mobile device."
I received this email about 15 mins after I ran the php page.
I turned off "2-step verification" and turned off "allow less secure apps". Nothing seems to help. Anyone please could help me?
I had the same issue last year: the code (VB.Net) was OK, so where the credentials. The problem was that gmail didn't like that some app in a web server far away (my hosting) where trying o use your same username.
I fixed it (in two different occasions) by:
Logging in gmail once from that server (using remote desktop).
Logging in here https://accounts.google.com/DisplayUnlockCaptcha from my pc to "unlock" remote connections.
After that test your code again.
I've been working on this problem for the past 2 days and everything that i tried is still not working. I'm trying to authenticate to an exchange server with php so i can send to outside domains.
If i disable authentication, i can send internally without any issues.
Here's the error
SMTP -> FROM SERVER:220 N-CAS1-13.company.domain Microsoft ESMTP MAIL Service ready at Sat, 20 Feb 2016 16:16:05 -0500
SMTP -> FROM SERVER: 250-N-CAS1-13.company.domain Hello [10.10.10.31] 250-SIZE 37748736 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-X- ANONYMOUSTLS 250-AUTH NTLM 250-X-EXPS GSSAPI NTLM 250-8BITMIME 250-BINARYMIME 250-CHUNKING 250 XRDST
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.
Here's the phpmailer code
require "phpmailer/class.phpmailer.php"; //include phpmailer class
//require "PHPMailer-5.2.14/PHPMailer-5.2.14/PHPMailerAutoload.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = false;
$mail->Host = "10.10.10.38";
$mail->Port = 25;
$mail->Username = "username";
$mail->Password = "cGhpbGltaWVzMjM2OTY5";
$mail->From = "name#companydomain.com";
$mail->FromName = "name";
$mail->SetFrom("name#companydomain.com", "name");
$mail->Subject = $_POST['company'].": (Time Sensitive)";
$mail->AddEmbeddedImage('trans2.png', 'logo', 'trans2.png ');
$mail->AddAttachment("docs/install.xlsx");
$mail->MsgHTML($message1.$message2.$message3);
// Send To
$mail->AddAddress($_POST['emailid'], ""); // Where to send it - Recipient
$mail->AddCC("person#companydomain.com");
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
I tried different version of phpmailer, i tried encoding the password with base64, i tried just the username, i tried the email as the username...Still nothing
The exchange server is on port 25 and it does not require SSL or TLS.
SMTP -> FROM SERVER: ... 250-AUTH NTLM
The server is only expecting NTLM authentication, not LOGIN, PLAIN or DIGEST-MD5 which could be used with only username and password. You would also need the NTLM realm and your workstation.
Unfortunately there is not much documentation about it but you might have a look at http://www.phpclasses.org/browse/file/31.html and look for NTLM to get the idea how to do this.
My code works when i use gmail has host, but for this project i have to use office365.com and i receive errors i do not know what to do with :
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->IsHTML(true);
$mail->Host = "smtp.office365.com"; // SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Port = 587; // set the SMTP port for the GMAIL
$mail->Username = "username"; // username
$mail->Password = "password"; // password
//works with this (gmail)
//$mail->Host = "smtp.gmail.com"; // SMTP server
//$mail->SMTPSecure = "tls"; // sets the prefix to the servier
//$mail->Port = 587; // set the SMTP port for the GMAIL
//$mail->Username = "username"; // GMAIL username
//$mail->Password = "password"; // GMAIL password
$mail->setFrom('someEmailAdress');
$mail->addReplyTo("someEmailAdress");
$mail->AddAddress('someEmailAdress');
$mail->Subject = $_POST['ActivityType']." ".$_POST['DealerName'];
$mail->Body = $message;
$mail->WordWrap = 400;
$mail->IsHTML(true);
$mail->SMTPDebug = 2;
$mail->Send();
this is the error i get
12014-12-22 18:15:39 SERVER -> CLIENT: 220 BY2PR05CA022.outlook.office365.com
Microsoft ESMTP MAIL Service ready at Mon, 22 Dec 2014 18:15:39 +0000
2014-12-22 18:15:39 CLIENT -> SERVER: EHLO 192.168.1.53
2014-12-22 18:15:39 SERVER -> CLIENT: 250-BY2PR05CA022.outlook.office365.com Hello [24.37.210.58]
250-SIZE 78643200
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250 CHUNKING
2014-12-22 18:15:39 CLIENT -> SERVER: STARTTLS
2014-12-22 18:15:39 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2014-12-22 18:15:39 CLIENT -> SERVER: QUIT
2014-12-22 18:15:40 SERVER -> CLIENT:
2014-12-22 18:15:40 SMTP ERROR: QUIT command failed:
SMTP connect() failed
been tryin to figure out whats going on, but theres really not much to search upon with the "general" error of quit command failed. Especially when gmail works fine, could it be on office365 side?
btw outlook is most restricted of them all specially when it comes to html emails which is the one u have set in ur options ,try first to send to something like gmail ,maybe yahoo but again it have some restriction but gmail works everytime without any probs ,u can also use something like fakesmtp to catch the sent email.
sorry can't comment yet but try these
https://github.com/PHPMailer/PHPMailer/issues/189
or may be a selinux thing
http://osticket.com/forum/discussion/77982/resolved-smtp-office365-issue
I'm getting the following error when trying to send an email from a web server running W2K server 2003 to smtp.mail.emea.microsoftonline.com
SMTP -> FROM SERVER:220 smtp.mail.emea.microsoftonline.com Microsoft ESMTP MAIL Service ready at Thu, 8 Oct 2009 01:00:53 -0700
SMTP -> FROM SERVER: 250-smtp.mail.emea.microsoftonline.com Hello [78.109.167.122] 250-SIZE 31457280 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-AUTH 250-8BITMIME 250-BINARYMIME 250 CHUNKING
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate.
Can anyone spot what is wrong? I have the the following set in php.ini as well:
[mail function]
; For Win32 only.
SMTP = smtp.mail.emea.microsoftonline.com
smtp_port = 587
; For Win32 only.
sendmail_from = enquiries#domain.com
require_once('class.phpmailer.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "smtp.mail.emea.microsoftonline.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Port = 587; // set the SMTP port for the server
$mail->Username = "enquiries#domain.com"; // username
$mail->Password = "Password"; // password
$mail->AddReplyTo('enquiries#domain.com', 'First Last');
$mail->AddAddress('myemail#gmail.com', 'John Doe');
$mail->SetFrom('enquiries#domain.com', 'First Last');
$mail->AddReplyTo('enquiries#domain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('examples/contents.html'));
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Try these manual steps first to see if you can connect at all:
http://technet.microsoft.com/en-us/library/aa995718(EXCHG.65).aspx
Also, this page:
http://www.gilham.org/Blog/Lists/Posts/Post.aspx?List=aab85845%2D88d2%2D4091%2D8088%2Da6bbce0a4304&ID=665
says that: The FROM address must use a SMTP domain of type “Authoritative” – this can be confirmed in Microsoft Online Administration Center, under the Users - Domains tab.
I've same problem some month ago. And the error caused by our SMTPSecure is used ntlm.
Don't forget to relay your mail server which it's allow to sent and receive mail from the web.
And recheck your account email and the password that is it right?