2

When I try to use PHPMailer on windows server 2012 at work to send report emails using SMTP I got Authentication unsuccessful error.

I'm using server administrator account on domain.

I'm very sure of the correction of the password.

check the code below:

require '../PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'mail.example.com';
$mail->Port = 25;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username@example.com";
$mail->Password = "yourpassword";
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer SMTP options test';
$mail->msgHTML($html_message);

I got the below response:

SERVER -> CLIENT: 220 exchangeserverhost.com Microsoft ESMTP MAIL Service ready at Tue, 3 Nov 2015 22:19:26 +0300
CLIENT -> SERVER: EHLO exchangeserverhost.com
SERVER -> CLIENT: 250-exchangeserverhost.com Hello 
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 SMTP server ready
CLIENT -> SERVER: EHLO exchangeserverhost.com
SERVER -> CLIENT: 250-exchangeserverhost.com Hello 
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 
CLIENT -> SERVER: 
SERVER -> CLIENT: 334 
CLIENT -> SERVER: ==
SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful
SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
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
Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Majed
  • 51
  • 1
  • 1
  • 8
  • Got the right username and/or password? I mean that seems to be the first thing to check. – Twisty Nov 04 '15 at 21:29
  • I would recommend to revisit the configuration for $mail->SMTPSecure = 'tls'; i think try first without the security parameter and see how it works. normally secured smtp causes issues if not properly configured at the hosting. – MansoorShiraz Nov 04 '15 at 21:40
  • If the STARTTLS didn't work, the subsequent EHLO would fail too, but it isn't, so it looks like your encryption is working fine. This looks like a simple wrong id/pass problem. BTW, those auth strings include your base64-encoded plain-text id and password, so I'd edit it out if I were you. – Synchro Nov 04 '15 at 23:14
  • Didn't work, I tried 3 accounts and all with the same error password failed. – Majed Nov 06 '15 at 19:45
  • Does this answer your question? [Can I send SMTP email through Office365 shared mailbox?](https://stackoverflow.com/questions/59735368/can-i-send-smtp-email-through-office365-shared-mailbox) – user956584 Sep 27 '20 at 11:06

2 Answers2

1

Problem Solved by changing $mail->SMTPAuth = true; to False.

$mail->SMTPAuth = False;

Majed
  • 51
  • 1
  • 1
  • 8
  • 1
    !!!! THIS IS SOLUTION !!!!!! mods keep delete my way how so solve this : Open the Microsoft 365 admin center and go to Users > Active users. Select the user, and in the flyout that appears, click Mail. In the Email apps section, click Manage email apps. Verify the Authenticated SMTP setting: unchecked = disabled, checked = enabled. When you're finished, click Save changes. – user956584 Sep 27 '20 at 11:01
0

If you are using Office 365 from GoDaddy and you have 2FA enabled, follow these steps in order to Disable 2FA. This solved my issue and it working even if SMTPAuth is true.