我正在尝试使用SendGrid为Laravel项目设置电子邮件。 遵循他们的文档时,我得到一个错误(https://sendgrid.com/docs/Integrate/Frameworks/laravel.html)
.env
看起来像这样
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=yea****
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="John Smith"
MAIL_FROM_ADDRESS=from@example.com
我得到的错误是这样的
ErrorException (E_WARNING)
stream_socket_enable_crypto(): Peer certificate CN=`****.****.***' did not match expected CN=`smtp.sendgrid.net'
/home/myusername/public_html/api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php
public function startTLS()
{
// STREAM_CRYPTO_METHOD_TLS_CLIENT only allow tls1.0 connections (some php versions)
// To support modern tls we allow explicit tls1.0, tls1.1, tls1.2
// Ssl3 and older are not allowed because they are vulnerable
// @TODO make tls arguments configurable
return stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);
}
Arguments
"stream_socket_enable_crypto(): Peer certificate CN=`****.****.***' did not match expected CN=`smtp.sendgrid.net'"
我通过使用此答案(https://stackoverflow.com/a/45315825)中提供的代码解决了该错误。 我知道这是不好的做法,但我又遇到了另一个错误。
Swift_TransportException
Failed to authenticate on SMTP server with username "yea****" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 Incorrect authentication data " in /home/myusername/public_html/a[i/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:456 Stack trace: #0
/home/myusername/public_html/api/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php
$message = 'Failed to authenticate on SMTP server with username "'.$this->username.'" using '.$count.' possible authenticators.';
foreach ($errors as $error) {
$message .= ' Authenticator '.$error[0].' returned '.$error[1].'.';
}
throw new Swift_TransportException($message);
}
}
对我来说,这似乎是某种身份验证错误,我使用的登录名与登录SendGrid仪表板时使用的凭据相同。
关于如何解决这些问题的任何想法?
答案 0 :(得分:1)
在这种情况下,我的解决方案是将用户名,密码和端口号双引号。
然后我又遇到了另一个错误,像这样:
''' 连接到tcp://smtp.hostx.com:465超时 '''
Connection to tcp://smtp.hostx.com:465 Timed Out
并且我将其更改为将MAIL_ENCRYPTION从 tls 更改为 ssl :
MAIL_ENCRYPTION = ssl
由于这篇文章太旧了,我希望这对其他人有帮助。