0

嗨,我使用 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';
    }

测试电子邮件类:

<?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: Connection could not be established with host smtp.sendgrid.net [Connection denied #111] {"exception":"[object] (Swift_TransportException(代码:0):无法与 /home/gthy6yfbfb5j/public_html/iotmarineapi/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/ 的主机 smtp.sendgrid.net [连接被拒绝 #111] 建立连接StreamBuffer.php:269) [堆栈跟踪]

4

1 回答 1

1

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

于 2020-03-24T10:31:38.840 回答