title: Laravel - How to fix "failed to authenticate on SMTP server" in Laravel 8 and Office365?
body: <p>In one of my Laravel 8 based applications, I want to switch from Mailgun to Office365 as a service change. Here is the information I have to integrate:</p>
  <pre><code>SMTP hostname: smtp.office365.com
  Port: 587
  Encryption method: STARTTLS
  SSL Protocol: OFF
  TLS Protocol: ON
  SMTP Username: smtp_user_email
  SMTP Password: smtp_password
  </code></pre>
  <p>So I write the following code in my .env file:</p>
  <pre><code>MAIL_MAILER=smtp
  MAIL_DRIVER=smtp
  MAIL_HOST=smtp.office365.com
  MAIL_PORT=587
  MAIL_USERNAME=smtp_user_email
  MAIL_PASSWORD=smtp_password
  MAIL_ENCRYPTION=tls
  MAIL_FROM_ADDRESS=smtp_user_email
  MAIL_FROM_NAME=&quot;${APP_NAME}&quot;
  </code></pre>
  <p>Then test the default <code>Forget Password</code> form of Laravel (so there should be no issue related to that form as it is the standard form of Laravel). But I receive the following response:</p>
  <blockquote>
  <p>Swift_TransportException
  Failed to authenticate on SMTP server with username &quot;smtp_user_email&quot; using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code &quot;535&quot;, with message &quot;535 5.7.139 Authentication unsuccessful, the user credentials were incorrect. [SI2PR02CA0047.apcprd02.prod.outlook.com] &quot;. Authenticator XOAUTH2 returned Expected response code 235 but got code &quot;535&quot;, with message &quot;535 5.7.3 Authentication unsuccessful [SI2PR02CA0047.apcprd02.prod.outlook.com] &quot;.</p>
  </blockquote>
  <p>I check the username and password, which is OK but I have no idea why it returns authenticationon related error!</p>
  <p>Does anyone why actually I missing that returns the error?</p>
  <ul>
  <li>Thanks</li>
  </ul>