首页 > 解决方案 > Sendgrid 不在服务器上发送邮件

问题描述

我第一次使用 Sendgrid,并将它与我的 Laravel 7 项目集成。我在 sendgrid 上注册并生成了 API KEY 并成功配置了.env文件。

现在我可以在本地主机上发送和接收邮件,但是当我在服务器上使用相同的配置时,它给了我以下错误

stream_socket_enable_crypto(): Peer certificate CN=`ip-107-180-95-117.ip.secureserver.net' did not match expected CN=`smtp.sendgrid.net 

我试图用谷歌搜索解决方案并遇到了这两个解决方案

1)用空字符串替换tls:tls.env文件中删除并用文件tls中的空字符串替换mail.php

2)在mail.php中添加以下代码

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
            'stream' => [
                'ssl' => [
                    'allow_self_signed' => true,
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                ],
            ],
        ],

这两种解决方案都导致我出现另一个错误

Failed to authenticate on SMTP server with username "apikey" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data
↵". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data

我的 Godaddy 服务器可能有什么问题,因为 sendgrid 正在本地主机上工作

标签: laravelsendgrid

解决方案


推荐阅读