预期响应代码 220,但得到代码“",消息为“"在 Laravel [英] Expected response code 220 but got code "", with message "" in Laravel

查看:43
本文介绍了预期响应代码 220,但得到代码“",消息为“"在 Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Laravel 邮件功能发送电子邮件.以下是我的app/config/mail.php文件设置.

I am using Laravel Mail function to send email. The following is my app/config/mail.php file settings.

'driver' => 'sendmail',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'email@gmail.com', 'name' => 'MyName'),
'encryption' => 'tls',
'username' => 'myUsername',
'password' => "password",
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,

控制器邮件方法

//Send Mail     
Mail::send('sendMail', array('key' => 'value'), function($message)
{
    $message->to('EmailId@hotmail.com', 'Sender Name')->subject('Welcome!');
});

当我运行代码时,它给了我以下错误消息:

When I run the code it gives me following error message:

Swift_TransportException

Swift_TransportException

预期响应代码为 220,但得到代码",消息为"

Expected response code 220 but got code "", with message ""

我在视图中创建了一个 SendMail.php 文件,其中包含一些数据.

I have created a SendMail.php file in view which contains some data.

如何解决此错误消息?

推荐答案

当您没有为 gmail 帐户启用两步验证(可以完成此处)您用于发送电子邮件.所以首先,启用两步验证,你可以找到大量的资源来启用两步验证.启用它后,您必须创建一个应用密码.并使用 .env 文件中的 app 密码.完成后,您的 .env 文件将类似于.

This problem can generally occur when you do not enable two step verification for the gmail account (which can be done here) you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file. When you are done with it, your .env file will look something like.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<your email address>>
MAIL_PASSWORD=<<app password>>
MAIL_ENCRYPTION=tls

和你的 mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => '<<your email>>', 'name' => '<<any name>>'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

这样做之后,运行php artisan config:cachephp artisan config:clear,然后检查,email 应该可以工作了.

After doing so, run php artisan config:cache and php artisan config:clear, then check, email should work.

这篇关于预期响应代码 220,但得到代码“",消息为“"在 Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆