我正在从Laravel项目发送电子邮件。在本地主机中,它可以完美运行,但是在使站点正常运行后,会出现以下错误。
The connection could not be established with host smtp.googlemail.com:stream_socket_client(): Peer certificate CN=`whm001.smart1marketing.com' did not match expected CN=`smtp.googlemail.com'
我正在使用与Laravel中相同的Google配置设置,我曾尝试清除所有缓存等,但没有解决方法
下面是.env文件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=my password
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME='LifeLoveAndOtherThings'
尝试这样更改:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
合适的解决方案:在createSmtpDriver
中的方法\vendor\laravel\framework\src\Illuminate\Mail\TransportManager.php
中,它从\config\mail.php
中获取密钥流,该密钥流随后用作\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php
中stream_context_create方法的自定义选项。
因此要设置键verify_peer,verify_peer_name和allow_self_signed来解决OP提到的错误,您可以将以下内容添加到\config\mail.php
:
'stream' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
],