Laravel 5.2和Valet - 无法发送电子邮件 - 无法找到套接字传输“plain”

时间:2016-07-18 14:56:40

标签: php sockets laravel email laravel-5.2

我正在使用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]

.Env文件:

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类型有关。非常感谢。

3 个答案:

答案 0 :(得分:1)

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

MAIL_ENCRYPTION=TLS

或者将其设置为NULL

答案 1 :(得分:0)

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

答案 2 :(得分:0)

PLAIN-是一种身份验证方法,但您将其用作MAIL_ENCRYPTION,只需在此处进行设置

class Foo-Iterator {…}

class Foo does Iterable {
    has $.max = 3;

    method val ( $index ) {
        ($index > $!max) ?? () !! ($index, "string $index")
    }

    method iterator (){
        # pass `self` for method calls or such
        # (could pass internal data additionally/instead)
        Foo-Iterator.new( :foo(self) )
    }
}

class Foo-Iterator does Iterator {
    # the mutating value
    has $!x = 0;

    # make it public only so we don't have
    # to mess with `new` or `BUILD`
    has $.foo is required;

    # only have the mutating logic in this object
    method pull-one() {
        $!foo.val( ++$!x ) || IterationEnd
    }
}

应该可以。