Laravel 发送网格 SMTP

Laravel Sendgrid SMTP

您好,我正在使用 Laravel 作为发送电子邮件的后端。 我按照本指南设法做到了:https://sendgrid.com/docs/for-developers/sending-email/laravel/

在我的本地 PC 上托管项目时效果很好,但是当项目托管在 GoDaddy 上时,我不断收到 500 服务器错误。我还从 Sendgrid 进行了发件人身份验证,但仍然收到 500 服务器错误。

API路线:

Route::get('/mail', 'Auth\v1\AuthController@sendMail');

控制器功能代码:

public function sendMail(){
        $data = ['message' => 'This is a test!'];
        Mail::to('john@example.com')->send(new TestEmail($data));
        return '200 OK';
    }

测试电子邮件 Class:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class TestEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

    public function __construct($data)
    {
        $this->data = $data;
    }

    public function build()
    {
        $address = 'janeexampexample@example.com';
        $subject = 'This is a demo!';
        $name = 'Jane Doe';

        return $this->view('emails.test')
                    ->from($address, $name)
                    ->cc($address, $name)
                    ->bcc($address, $name)
                    ->replyTo($address, $name)
                    ->subject($subject)
                    ->with([ 'message' => $this->data['message'] ]);
    }
}

我收到以下错误: [2019-08-02 11:37:36] production.ERROR: 无法与主机建立连接 smtp.sendgrid.net [连接被拒绝 #111] {"exception":"[object] (Swift_TransportException(代码:0):无法与主机 smtp.sendgrid.net [Connection refused #111] at /home/gthy6yfbfb5j/public_html/iotmarineapi/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269 建立连接) [堆栈跟踪]

解决方法是使用 Sendgrid API,因为需要在 GoDaddy 中正确设置 SMTP。