Created
May 27, 2020 14:02
-
-
Save ADmad/6727d9c4be5cb58a021ce808228f0e2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Mailer/Transport/SmtpTransport.php b/src/Mailer/Transport/SmtpTransport.php | |
index 59f4b8041f..d298a0dab9 100644 | |
--- a/src/Mailer/Transport/SmtpTransport.php | |
+++ b/src/Mailer/Transport/SmtpTransport.php | |
@@ -271,26 +271,43 @@ class SmtpTransport extends AbstractTransport | |
*/ | |
protected function _auth(): void | |
{ | |
- if (isset($this->_config['username'], $this->_config['password'])) { | |
- $replyCode = (string)$this->_smtpSend('AUTH LOGIN', '334|500|502|504'); | |
- if ($replyCode === '334') { | |
- try { | |
- $this->_smtpSend(base64_encode($this->_config['username']), '334'); | |
- } catch (SocketException $e) { | |
- throw new SocketException('SMTP server did not accept the username.', null, $e); | |
- } | |
- try { | |
- $this->_smtpSend(base64_encode($this->_config['password']), '235'); | |
- } catch (SocketException $e) { | |
- throw new SocketException('SMTP server did not accept the password.', null, $e); | |
- } | |
- } elseif ($replyCode === '504') { | |
- throw new SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS.'); | |
- } else { | |
- throw new SocketException( | |
- 'AUTH command not recognized or not implemented, SMTP server may not require authentication.' | |
- ); | |
+ if (!isset($this->_config['username'], $this->_config['password'])) { | |
+ return; | |
+ } | |
+ | |
+ $username = $this->_config['username']; | |
+ $password = $this->_config['password']; | |
+ | |
+ $replyCode = $this->_smtpSend( | |
+ sprintf( | |
+ 'AUTH PLAIN %s', | |
+ base64_encode($username . chr(0) . $username . chr(0) . $password) | |
+ ), | |
+ '235|504' | |
+ ); | |
+ | |
+ if ($replyCode === '235') { | |
+ return; | |
+ } | |
+ | |
+ $replyCode = $this->_smtpSend('AUTH LOGIN', '334|500|502|504'); | |
+ if ($replyCode === '334') { | |
+ try { | |
+ $this->_smtpSend(base64_encode($username), '334'); | |
+ } catch (SocketException $e) { | |
+ throw new SocketException('SMTP server did not accept the username.', null, $e); | |
+ } | |
+ try { | |
+ $this->_smtpSend(base64_encode($password), '235'); | |
+ } catch (SocketException $e) { | |
+ throw new SocketException('SMTP server did not accept the password.', null, $e); | |
} | |
+ } elseif ($replyCode === '504') { | |
+ throw new SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS.'); | |
+ } else { | |
+ throw new SocketException( | |
+ 'AUTH command not recognized or not implemented, SMTP server may not require authentication.' | |
+ ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment