预期响应代码 250 但得到代码“550”,消息“不允许 550 未经身份验证的发件人”与 Laravel 7 & SendGrid

Expected response code 250 but got code "550", with message "550 Unauthenticated senders not allowed" with Laravel 7 & SendGrid

我真的很难弄明白。我最近开始了一个新的 Laravel 7 项目,我真的很难让 SendGrid SMTP 中继与该项目一起正常工作。

我查看了 Whosebug、SendGrid 文档和 Google,但我仍在努力寻找可行的解决方案。

我的 .ENV 文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD={{apikey from SendGrid}}
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"
MAIL_FROM_ADDRESS=no-reply@galacticdigital.co.za

我的config/mail.php文件:

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.sendgrid.net'), 
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('apikey'),
            'password' => env('{{apikey from SendGrid}}'),
            'timeout' => null,
        ],

预期响应代码 250 但收到代码“550”,消息“不允许 550 未经身份验证的发件人”

即使在 运行 之后我仍然收到此错误: php artisan cache:clear php artisan config:cache

有没有人可以帮助我了解这里发生的事情以及我如何解决它。我仍在忙于学习 Laravel,但我还不是最擅长使用它的人。

您正在请求名为 apikey{{apikey from SendGrid}} 的 ENV 常量。

它们是值而不是名称。因此在 ENV 文件中找不到它们。

更正以下行:

[   
    // .....
    'username' => env('apikey'),
    'password' => env('{{apikey from SendGrid}}'),
    // .....
]

[   
    // .....
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    // .....
]

并确保您的 ENV 文件中的 API 凭证是正确的。