Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPMailer not connecting to Office365 #189

Closed
jfha73 opened this issue Feb 26, 2014 · 57 comments
Closed

PHPMailer not connecting to Office365 #189

jfha73 opened this issue Feb 26, 2014 · 57 comments

Comments

@jfha73
Copy link

jfha73 commented Feb 26, 2014

Hey guys,

I'm trying to connect to Office365 using the settings given by outlook.office365.com:

Server: smtp.office365.com
Port: 587
Security: TLS

I tried that but when I use TLS it doesn't connect and when I use STARTTLS I get a Couldn't authenticate.

I know for sure I'm using the correct Username=>Email and Password, but I can't get it to connect.

For more information when I have to use a local non secure, no login needed server it works, but when I try a TLS it doesn't.

Any ideas?

Thanks.

@Synchro
Copy link
Member

Synchro commented Feb 26, 2014

Code? I expect you should use the same setup as for gmail since ports and protocols are the same - give that code a try, just swap out the hostname.

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

I just did and I'm getting this, my code is at the end, I get the variables from a form:

SMTP -> FROM SERVER:220 BLUPR06CA005.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 26 Feb 2014 18:17:55 +0000
CLIENT -> SMTP: EHLO localhost
SMTP -> FROM SERVER:250-BLUPR06CA005.outlook.office365.com Hello [74.8.80.62]250-SIZE 78643200250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 CHUNKING
CLIENT -> SMTP: AUTH LOGIN
SMTP -> FROM SERVER:504 5.7.4 Unrecognized authentication type
SMTP -> ERROR: AUTH command failed: 504 5.7.4 Unrecognized authentication type
CLIENT -> SMTP: QUIT
SMTP -> FROM SERVER:221 2.0.0 Service closing transmission channel

So how can I set the Authentication type with PHPMailer?

This is my code:

<?php
//require('phpmailer/class.phpmailer.php');
require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer(true); 

$mail->SMTPSecure = "starttls";
$mail->SMTPAuth   = true;
$mail->Username   = $_POST['from'];
$mail->Password   = $_POST['pwd'];
$mail_from        = $_POST['from'];
$subject          = $_POST['subject'];
$body             = $_POST['message'];
$mail_to          = $_POST['to'];

$mail->IsSMTP(); 

try {
  $mail->Host       = "smtp.office365.com"; // SMTP server
  $mail->Port = "587"; //SMTP Port
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->Debugoutput = 'html';
  $mail->AddAddress($mail_to, '');
  $mail->SetFrom($mail_from); 
  $mail->Subject = $subject;
  $mail->MsgHTML($body);
  $mail->Send();
  echo "Message Sent...<p></p>\n";
  echo "Click <a href=\"index.php\">here</a> to send another email";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
  echo "<p>Using Username: ".$mail->Username."</p>";
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
?>

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

Found it in the documentation, so I tried PLAIN and it didn't work either.

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

Neither do NTLM and CRAM-MD5, so any ideas?

And before you ask, yes I did include the realm and workstation with NTLM

@Synchro
Copy link
Member

Synchro commented Feb 26, 2014

Don't do $mail->SMTPSecure = "starttls";, do $mail->SMTPSecure = "tls";, port should be an int. Really, use the gmail example code as it's got all that set up correctly already. It looks like you're using some old version.

MS docs are here

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

I tried both, tls won't connect to office365, starttls connects but it doesn't authenticate.

Also, I tested the smtp class from phpclasses.org (http:https://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html) and it works, so it has to do with the smtp class that PHPMailer uses.

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

This is what I get when I use tls:

SMTP -> FROM SERVER:220 BLUPR06CA017.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 26 Feb 2014 19:46:08 +0000
CLIENT -> SMTP: EHLO localhost
SMTP -> FROM SERVER:250-BLUPR06CA017.outlook.office365.com Hello [74.8.80.62]250-SIZE 78643200250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 CHUNKING
CLIENT -> SMTP: STARTTLS
SMTP -> FROM SERVER:220 2.0.0 SMTP server ready
CLIENT -> SMTP: QUIT
SMTP -> FROM SERVER:
SMTP -> ERROR: QUIT command failed:
SMTP Error: Could not connect to SMTP host.

For tls it looks like PHPMailer quits after the server says it's ready.

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

I just downloaded the master version and tried it but I keep getting the same error and I am using the gmail example for this purpose.

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

Also, I found this problem when I downloaded and installed PHPList that uses this class and it couldn't connect either, so it's not only me or my code, there is PHPList also with this problem.

@Synchro
Copy link
Member

Synchro commented Feb 26, 2014

Using 'starttls' looks like it's getting further because it's not a valid encryption option so it's falling back to unencrypted authentication, which is not permitted on port 587, so it's then failing.

Can you check the response given by the startTLS method? Just make it echo something obvious or set a breakpoint on it. The 220 response is correct, and the only other thing in there is the call to enable stream encryption, and if that fails it will terminate the connection. What PHP version are you running?

@Synchro
Copy link
Member

Synchro commented Feb 26, 2014

Can you get a transcript out of the phpclasses code so we can see what's different?

@jfha73
Copy link
Author

jfha73 commented Feb 26, 2014

The original class can be found at http:https://www.phpclasses.org, the one
the webapp I'm using where it works is this (maybe older)

@Synchro
Copy link
Member

Synchro commented Feb 27, 2014

No I mean a transcript of the SMTP conversation it has, like you posted for the PHPMailer debug output (just set your instance's debug property to true).

@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

I had to ask the developer of the webapp it uses it, I turned it on but
got no debug, so I'm waiting for him to tell me how can I get it.

@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

Here it is a working TLS connection with Office365:

Resolving SMTP server domain "smtp.office365.com"...
Connecting to host address "132.245.8.12" port 587...
Connected to SMTP server "smtp.office365.com".
S 220 BLUPR07CA031.outlook.office365.com Microsoft ESMTP MAIL Service 
ready at Thu, 27 Feb 2014 18:00:37 +0000
C EHLO localhost
S 250-BLUPR07CA031.outlook.office365.com Hello [xxx.xxx.xxx.xxx]
S 250-SIZE 78643200
S 250-PIPELINING
S 250-DSN
S 250-ENHANCEDSTATUSCODES
S 250-STARTTLS
S 250-8BITMIME
S 250-BINARYMIME
S 250 CHUNKING
C STARTTLS
S 220 2.0.0 SMTP server ready
Starting TLS cryptograpic protocol
TLS started
C EHLO localhost
S 250-BLUPR07CA031.outlook.office365.com Hello [74.8.80.62]
S 250-SIZE 78643200
S 250-PIPELINING
S 250-DSN
S 250-ENHANCEDSTATUSCODES
S 250-AUTH LOGIN
S 250-8BITMIME
S 250-BINARYMIME
S 250 CHUNKING
C AUTH LOGIN
S 334 VXNlcm5hbWU6
C amZoZXJuYW5kZXpAaGVhbHRoc29sdXRpb25zLm9yZw==
S 334 UGFzc3dvcmQ6
C Sm9yMTA3M0xpeg==
S 235 2.7.0 Authentication successful
C MAIL FROM:<[email protected]>
C RCPT TO:<[email protected]>
C DATA
S 250 2.1.0 Sender OK
S 250 2.1.5 Recipient OK
S 354 Start mail input; end with <CRLF>.<CRLF>
C From: [email protected]
To: [email protected]
Subject: Testing Manuel Lemos' SMTP class
Date: Thu, 27 Feb 2014 13:00:38 Eastern Standard Time


C Hello [email protected],

It is just to let you know that your SMTP class is working just fine.

Bye.

C
.
S 250 2.6.0 
<9f632b06-9e00-4360-aa2e-159b1da04451@CO1PR02MB144.namprd02.prod.outlook.com> 
[InternalId=31988916420822, 
Hostname=CO1PR02MB144.namprd02.prod.outlook.com] Queued mail for delivery
C QUIT
S 221 2.0.0 Service closing transmission channel
Disconnected.
Message sent to [email protected] OK.

@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

What made it all work was this other library: SASL

@Synchro
Copy link
Member

Synchro commented Feb 27, 2014

That's a bit odd. PHPMailer doesn't need SASL as it has built-in support for the LOGIN auth method.

Can you try replacing the startTLS function with this:

    public function startTLS()
    {
        if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
echo 'STARTTLS failed'; exit;
            return false;
        }
        // Begin encrypted connection
        if (!stream_socket_enable_crypto(
            $this->smtp_conn,
            true,
            STREAM_CRYPTO_METHOD_TLS_CLIENT
        )) {
echo 'enable crypto failed'; exit;
            return false;
        }
echo 'STARTTLS OK'; exit;
        return true;
    }

so we can find out what it's unhappy about.

@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

I replaced it and I'm still not sending, I get this:

SERVER -> CLIENT: 220 BN1PR07CA016.outlook.office365.com Microsoft ESMTP 
MAIL Service ready at Thu, 27 Feb 2014 18:53:11 +0000
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-BN1PR07CA016.outlook.office365.com Hello 
[74.8.80.62]250-SIZE 
78643200250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 
CHUNKING
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 SMTP server ready
STARTTLS OKCLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel

I do see the STARTTLS OK that you put in it, but it quits after that, no
email is sent.

@Synchro
Copy link
Member

Synchro commented Feb 27, 2014

It won't work because those lines I added will make it exit immediately - the exercise was to find out where it's getting to, fixing it comes later. Anyway, we now know that STARTTLS is successful, so the problem is occurring later.

Remove those three 'echo' lines. In in the smtpConnect function in the PHPMailer class, I suspect it's throwing an exception that is not shown in debug output. So we can see that, find this section near the end of that function:

                } catch (phpmailerException $e) {
                    $lastexception = $e;
                    //We must have connected, but then failed TLS or Auth, so close connection nicely
                    $this->smtp->quit();
                }

and change it to:

                } catch (phpmailerException $e) {
var_dump($e);
                    $lastexception = $e;
                    //We must have connected, but then failed TLS or Auth, so close connection nicely
                    $this->smtp->quit();
                }

The var_dump output will tell us why it's killing the connection.

@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

What do you know, i erased the 3 echoes, added the var_dump($e) and it
worked, here is the full transcript:

SERVER -> CLIENT: 220 BN1PR07CA024.outlook.office365.com Microsoft ESMTP 
MAIL Service ready at Thu, 27 Feb 2014 20:06:13 +0000
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-BN1PR07CA024.outlook.office365.com Hello 
[74.8.80.62]250-SIZE 
78643200250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250 
CHUNKING
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 SMTP server ready
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-BN1PR07CA024.outlook.office365.com Hello 
[74.8.80.62]250-SIZE 
78643200250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH 
LOGIN250-8BITMIME250-BINARYMIME250 CHUNKING
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: SkZIZXJuYW5kZXpAaGVhbHRoc29sdXRpb25zLm9yZw==
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: Sm9yMTA3M0xpeg==
SERVER -> CLIENT: 235 2.7.0 Authentication successful
CLIENT -> SERVER: MAIL FROM:<[email protected]>
SERVER -> CLIENT: 250 2.1.0 Sender OK
CLIENT -> SERVER: RCPT TO:<[email protected]>
SERVER -> CLIENT: 250 2.1.5 Recipient OK
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
CLIENT -> SERVER: Date: Thu, 27 Feb 2014 15:06:13 -0500
CLIENT -> SERVER: Return-Path: <[email protected]>
CLIENT -> SERVER: To: [email protected]
CLIENT -> SERVER: From: [email protected]
CLIENT -> SERVER: Subject: Testing O365 SMTP
CLIENT -> SERVER: Message-ID: <74caa31960275e0f9cca3578f4f63dec@localhost>
CLIENT -> SERVER: X-Priority: 3
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.7 
(https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_74caa31960275e0f9cca3578f4f63dec"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_74caa31960275e0f9cca3578f4f63dec
CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: This is a test
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_74caa31960275e0f9cca3578f4f63dec
CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: <p>This is a test</p>
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_74caa31960275e0f9cca3578f4f63dec--
CLIENT -> SERVER:
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 2.6.0 <74caa31960275e0f9cca3578f4f63dec@localhost> 
[InternalId=31894427142201, 
Hostname=BN1PR02MB135.namprd02.prod.outlook.com] Queued mail for delivery
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
Message Sent...

@Synchro
Copy link
Member

Synchro commented Feb 27, 2014

Now that's weird - so it's now working with the original, unchanged code! The var_dump isn't ever being run because it's succeeding in connecting, so you can delete it now.

I'm glad it's working, but I'd be happier if I knew why it wasn't before!

@Synchro Synchro closed this as completed Feb 27, 2014
@jfha73
Copy link
Author

jfha73 commented Feb 27, 2014

Thanks Marcus.

@ooxi
Copy link

ooxi commented Feb 28, 2014

@Synchro this is speculation but we are experiencing huge troubles with the Office 365 SMTP connector ourselfs. It looks like the deployed servers are not stable at all.

@Synchro
Copy link
Member

Synchro commented Feb 28, 2014

Good to know, thanks! Microsoft making a mess of something, who'd have guessed?!

@jfha73
Copy link
Author

jfha73 commented Feb 28, 2014

Another question,

I'm testing PHPList to connect to Office 365, it uses PHPMailer, I
changed the phpmailer class to the one I had on my working test server
but when I try to test email sending, I'm getting this:

5.5.4 Invalid domain name SMTP connect() failed.

Is there a way I can set this up in PHPMailer?

@Synchro
Copy link
Member

Synchro commented Feb 28, 2014

That just sounds like you have a typo in a hostname somewhere in your config.

@jfha73
Copy link
Author

jfha73 commented Feb 28, 2014

I just checked and it's good everywhere.

@Synchro
Copy link
Member

Synchro commented Feb 28, 2014

SMTP transcript?

@jfha73
Copy link
Author

jfha73 commented Feb 28, 2014

I got it, check this:

2014-02-28 16:12:49 CLIENT -> SERVER: EHLO server/phplist/lists
2014-02-28 16:12:54 SERVER -> CLIENT:
2014-02-28 16:12:54 SMTP ERROR: EHLO command failed:
2014-02-28 16:12:54 CLIENT -> SERVER: HELO server/phplist/lists
2014-02-28 16:12:54 SERVER -> CLIENT: 501 5.5.4 Invalid domain name
2014-02-28 16:12:54 SMTP ERROR: HELO command failed: 501 5.5.4 Invalid domain name
2014-02-28 16:12:54 CLIENT -> SERVER: STARTTLS
2014-02-28 16:12:59 SERVER -> CLIENT:

Somewhere in the config, PHPList is sending my local server name and
path to Office 365 instead of the external IP of my NAT.

@Synchro
Copy link
Member

Synchro commented Feb 28, 2014

That explains it; guess that's a PHPList bug or misconfig.

@jfha73
Copy link
Author

jfha73 commented Feb 28, 2014

Yep, I'm already in contact with them.

@ghost
Copy link

ghost commented May 12, 2014

Hi @jfha73, Did you manage to get PHPList working with Office 365? I'm having a few issues creating the connection through SMTP.

CLIENT -> SMTP: AUTH LOGIN 
SMTP -> ERROR: AUTH not accepted from server: 
CLIENT -> SMTP: RSET 
SMTP -> FROM SERVER:504 5.7.4 Unrecognized authentication type 
SMTP -> ERROR: RSET failed: 504 5.7.4 Unrecognized authentication type 
CLIENT -> SMTP: MAIL FROM: 
SMTP -> FROM SERVER:250 2.0.0 Resetting 
CLIENT -> SMTP: RCPT TO: 
SMTP -> FROM SERVER:530 5.7.1 Client was not authenticated 
SMTP -> ERROR: RCPT not accepted from server: 530 5.7.1 Client was not authenticated 

@jfha73
Copy link
Author

jfha73 commented May 12, 2014

I don't remember, but I think I used another version of PHPMailer (the
one that PHPMailer has for GMail), we are not using PHPList anymore,
they decided to go with an old listserv instead.

I hope that helps.

Signature

Jorge Hernandez

@jfha73
Copy link
Author

jfha73 commented May 13, 2014

I’m starting to remember, after I downloaded the latest version of PHPMailer and replaced the one that comes with it, I changed the file where it calls it and changed it for what it says in this example

Don’t ask me what the file is where PHPList calls it, because that is impossible without a copy of PHPList and since we are not using it, I’m not going to download it again.

Good luck and let me know how it went.

Jorge Hernandez

@Synchro
Copy link
Member

Synchro commented May 14, 2014

That example is old - this is the updated version of the same script.

@ghost
Copy link

ghost commented May 14, 2014

Thanks for the replies. I got this to work by doing the following:

I edited the file sendemaillib.php and added the following lines and it seems to be working now:

       //Tell PHPMailer to use SMTP
  $mail->isSMTP();

  //Set the encryption system to use - ssl (deprecated) or tls
  $mail->SMTPSecure = 'tls';

@sujithayur
Copy link

open php.ini file and check php_openssl.dll is enabled,

if not found add this line

extension=php_openssl.dll

@DouglasTonini
Copy link

RESOLVIDO!

Utilizando classe padrão de envio PHPMailer_5.2.1/class.phpmailer.php

Exemplo:

IsSMTP(); // telling the class to use SMTP $mail->Host = "smtp.office365.com"; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "tls"; // sets the prefix to the servier $mail->Host = "smtp.office365.com"; // sets GMAIL as the SMTP server $mail->Port = 587; // set the SMTP port for the OUTLOOK 465 server $mail->Username = "[email protected]"; // OUTLOOK 465 username $mail->Password = "sua senha"; // OUTLOOK 465 password $mail->SetFrom('[email protected]', 'First Last'); $mail->AddReplyTo("[email protected]","First Last"); $mail->Subject = "PHPMailer Test Subject via smtp (OUTLOOK 465), basic"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $body = 'teste'; $mail->MsgHTML($body); $address = "[email protected]"; $mail->AddAddress($address, "NOME"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017

for me don´t work.
i am using 5.2.23 version but the same error

2017-05-21 05:36:41 Connection: opening to smtp.office365.com:587, timeout=300, options=array ( )
2017-05-21 05:36:41 Connection: opened
2017-05-21 05:36:41 SERVER -> CLIENT: 220 DM5PR17CA0038.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 21 May 2017 05:36:41 +0000
2017-05-21 05:36:41 CLIENT -> SERVER: EHLO www.strategypartners.com.br
2017-05-21 05:36:41 SERVER -> CLIENT: 250-DM5PR17CA0038.outlook.office365.com Hello [13.65.45.30] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-STARTTLS 250-8BITMIME 250-BINARYMIME 250 CHUNKING
2017-05-21 05:36:41 CLIENT -> SERVER: STARTTLS
2017-05-21 05:36:41 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2017-05-21 05:36:41 CLIENT -> SERVER: EHLO www.strategypartners.com.br
2017-05-21 05:36:41 SERVER -> CLIENT: 250-DM5PR17CA0038.outlook.office365.com Hello [13.65.45.30] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-AUTH LOGIN 250-8BITMIME 250-BINARYMIME 250 CHUNKING
2017-05-21 05:36:41 CLIENT -> SERVER: AUTH LOGIN
2017-05-21 05:36:41 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2017-05-21 05:36:41 CLIENT -> SERVER: xxx==
2017-05-21 05:36:41 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2017-05-21 05:36:41 CLIENT -> SERVER: xxx
2017-05-21 05:36:51 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [DM5PR17CA0038.namprd17.prod.outlook.com]
2017-05-21 05:36:51 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [DM5PR17CA0038.namprd17.prod.outlook.com]
2017-05-21 05:36:51 SMTP Error: Could not authenticate.
2017-05-21 05:36:51 CLIENT -> SERVER: QUIT
2017-05-21 05:36:51 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2017-05-21 05:36:51 Connection: closed
2017-05-21 05:36:51 SMTP Error: Could not authenticate.

@lucianobonfim
Copy link

Any ideas?

Thanks.

@Synchro
Copy link
Member

Synchro commented May 22, 2017

Yes, you've got the wrong username or password. Please don't hijack old, closed tickets. Also, your password was easily decoded from that transcript, so you should change your password.

@DouglasTonini
Copy link

Verifique se a conta (email de autenticação) foi criada corretamente.. Parece bobagem, mas as vezes é um pequeno descuido.

https://login.microsoftonline.com e veja se sua caixa postal está ativa.

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@DouglasTonini
Copy link

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@DouglasTonini
Copy link

DouglasTonini commented May 22, 2017 via email

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@DouglasTonini
Copy link

DouglasTonini commented May 22, 2017 via email

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@DouglasTonini
Copy link

DouglasTonini commented May 22, 2017 via email

@lucianobonfim
Copy link

lucianobonfim commented May 22, 2017 via email

@DouglasTonini
Copy link

DouglasTonini commented May 22, 2017 via email

@kazakbala
Copy link

kazakbala commented Apr 9, 2018

I had same problem with Microsoft Exchange with TLS.
Try to auth without domain name.
I just changed
$mail->Username = '[email protected]';
to
$mail->Username = 'user';
And its works

@imManish
Copy link

i am having same issue with sending email through office365 smtp

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.office365.com";
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "*******";

$ppbuzzyuser_email=$_POST['buzzyuser_email'];
$mail->FromName = 'Invitation for Certefied';
$mail->addAddress($ppbuzzyuser_email);            
$mail->Subject = 'Do not reply on this message.';

$mail->Body   = '<div style="background:#eee; width:551px; height:277px; margin:0 auto;">
  <h3  style="text-align:center; color:#2f4050; font-size:22px; padding-top:60px;">Dear '.$ppbuzzyuser_email.'</h3>
  <p style="text-align:center; color:#2f4050; font-size:17px; margin-top:0px;">Your Employer <strong>'.$session_buzzyuser_company.'</strong> requests for you to join CertEfied. CertEfied is '.$session_buzzyuser_company.'&#39;s compliance software program, that helps you and '.$session_buzzyuser_company.' store employee licences and qualifications quickly and easily. </p>
  <p style="text-align:center; color:#2f4050; font-size:17px; margin-top:0px;">
    CertEfied is able to store your qualifications within your own individual profile for free. This will allow you to share your professional qualifications or licences with '.$session_buzzyuser_company.' quickly and easily. Just simply upload all qualifications your employer requires access to and have CertEfied look after automatically synchronising it to your employer’s profile.
  </p>
  <p style="text-align:center; color:#2f4050; font-size:17px; margin-top:0px;">
  If you undertake work with more than one employer who requires access to your credentials, you may add yourself / request to be added to their CertEfied company profile. No need to re register twice!
  </p>
  <p style="text-align:center; color:#2f4050; font-size:17px; margin-top:0px;">
  If you wish to sign up using this link <a  href="'.$buzzysiteurl.'/index.php?company-invite='.$session_user_id.'">Register here</a> this means you will be automatically be connected to '.$session_buzzyuser_company.' so you can start uploading your qualifications and licences for you and your employer right away. This helps you to remain safe and compliant at work.
  </p>
  Regards
  <p style="text-align:center; color:#2f4050; font-size:17px; margin-top:0px;">
  The CertEfied Team
  </p>
</div>';

$mail->AltBody = 'Hello user, You are now member of Certefied community. ';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent successfully.';
}
exit;
header('Location: '.$link_prefix.'page.php?user-id='.$session_user_id.'&invite-sent=true');
}

Anyone can help me on this?

@DouglasTonini
Copy link

DouglasTonini commented Sep 11, 2018 via email

@jaimemtzag
Copy link

I made it work, doing the next steps:

  1. Use de Phpmailer version 5.2 - PHPMailer-5.2-stable
  2. Open the example - ssl_options.php / fill with your office365 acount and pwd
  3. Use the next configuration, and it works - because it avoid checking a certificate SSL - :

$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';

$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants