Laravel 5.2 和代客 - 无法发送电子邮件 - 找不到套接字传输“普通”


Laravel 5.2 and Valet - unable to send email - Unable to find the socket transport "plain"

我正在使用Laravel Valet和Laravel 5.2。当我尝试触发发送电子邮件时,我收到此错误:

Swift_TransportException in StreamBuffer.php line 269:
Connection could not be established with host mailtrap.io 
[Unable to find the socket transport "plain" - did you forget to enable 
it when you configured PHP? #1]

.环境文件:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=whatTheyGaveMe
MAIL_PASSWORD=whatTheyGaveMe
MAIL_ENCRYPTION=PLAIN

邮件功能:

public function sendClinicEmail($id, $emailType, $data)
{
    $user = User::findOrFail($id);
    Mail::queue('emails.clinic.' . $emailType . '', ['user' => $user, 'data' => $data], 
        function ($m) use ($user, $data) {
        $brandName = Config::get('brand.name');
        $m->from('hello@app.com', '' . $brandName . '');
        $m->to($user->email, $user->name)->subject($data['subject']);
    });
}

请问我该如何解决这个问题?无论我使用哪种类型的 AUTH,它仍然返回相同的错误,只是与 AUTH 类型有关。非常感谢。

此加密值设置为 plain,在这种情况下可能无效。你可以试试这个:

MAIL_ENCRYPTION=TLS

或将其设置为 NULL

PLAIN - 是一种身份验证方法,但您可以将其用作MAIL_ENCRYPTION,只需设置在那里

MAIL_ENCRYPTION=NULL

这应该可以正常工作。

对于在 2018 年或之后遇到此错误并在 google 上找到此错误的任何人,我的解决方法是将主机从 mailtrap.io 更改为 smtp.mailtrap.io。可以在此处找到此更改的原因:https://mailtrap.io/blog/2018-03-09-why-mailtrap-updated-its-smtp-host