laravel 错误消息:预期响应代码 220,但得到一个空响应”,异常“Swift_TransportException”,
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54787348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error Message: Expected response code 220 but got an empty response" with exception "Swift_TransportException",
提问by Payne
I am following a tutorial to build an API using passport authentication on enter link description hereI have followed the part 1 and walking through the part 2 with account confirmation and notificationsbut eventually got a problem when I am testing on POSTMAN. The issue is, it does add to the database only that there is no mail sent with the error. I don't know of there is any configuration I need to do in .env or mail.php. As I tried to configure the email address, STMP and password. The same error is displayed again and most issues I have seen on here are quite different as most are pertaining to mail.php and .env which I have no idea as there is no such on the tutorial link and I even tried to alter the mail.php and .env, I ran php artisan cache:clearbut the same error is displayed.
我正在学习使用护照身份验证构建 API 的教程,在此处输入链接描述我遵循了第 1 部分并通过帐户确认和通知浏览了第 2 部分,但最终在我在 POSTMAN 上进行测试时遇到了问题。问题是,它确实会添加到数据库中,只是没有发送带有错误的邮件。我不知道我需要在 .env 或 mail.php 中做任何配置。当我尝试配置电子邮件地址、STMP 和密码时。同样的错误再次显示,我在这里看到的大多数问题都大不相同,因为大多数问题都与 mail.php 和 .env 有关,我不知道,因为教程链接上没有这样的,我什至试图更改邮件.php 和 .env,我运行php artisan cache:clear但显示相同的错误。
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SignupActivate extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$url = url('/api/auth/signup/activate/'.$notifiable->activation_token);
return (new MailMessage)
->subject('Confirm your account')
->line('Thanks for signup! Please before you begin, you must confirm your account.')
->action('Confirm Account', url($url))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
I did also, two ways authentication Mail.php
我也是,两种方式认证 Mail.php
return [
返回 [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Payne Curtis'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
];
.env
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=XXXXXXXXXXXXXXX
MAIL_ENCRYPTION=null
回答by Abdulkabir Ojulari
I think I can figure out your problem here. What you need to do is to make a strict setting to comply with the mail.php
我想我可以在这里找出你的问题。您需要做的是进行严格的设置以符合mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Payne Curtis'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
Therefore change your .env to the following;
因此,将您的 .env 更改为以下内容;
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=gjcltiocmmqoutfi
MAIL_ENCRYPTION=tls
MAIL_ENCRYPTION=tlsis very essential and needs to be added to the .env file
MAIL_ENCRYPTION=tls非常必要,需要添加到 .env 文件中