邮件未从我的laravel项目发送

问题描述 投票:0回答:1

我正在从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'
php laravel
1个回答
0
投票

尝试这样更改:

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,
        ],
    ],
© www.soinside.com 2019 - 2024. All rights reserved.