错误消息:预期响应代码 220 但得到空响应”,异常 "Swift_TransportException",
error Message: Expected response code 220 but got an empty response" with exception "Swift_TransportException",
I am following a tutorial to build an API using passport authentication on enter link description here
我已经完成了第 1 部分并通过 帐户确认和通知 完成了第 2 部分,但是当我在 POSTMAN 上进行测试时最终遇到了问题。问题是,它确实只是在没有发送错误邮件的情况下才添加到数据库中。我不知道我需要在 .env 或 mail.php 中做任何配置。当我尝试配置电子邮件地址、STMP 和密码时。再次显示相同的错误,我在这里看到的大多数问题都非常不同,因为大多数问题都与 mail.php 和 .env 有关,我不知道,因为教程 link 上没有这样的问题,我甚至试图改变 mail.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 [
//
];
}
}
我也做过,两种方式认证
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', 'username@gmail.com'),
'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
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=XXXXXXXXXXXXXXX
MAIL_ENCRYPTION=null
我想我可以在这里解决您的问题。您需要做的是严格设置以符合 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', 'username@gmail.com'),
'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 更改为以下内容;
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abdulkabirojulari@gmail.com
MAIL_PASSWORD=gjcltiocmmqoutfi
MAIL_ENCRYPTION=tls
MAIL_ENCRYPTION=tls非常必要,需要添加到.env文件中
<?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 [
//
];
}
}
我也做过,两种方式认证 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', 'username@gmail.com'),
'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
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=XXXXXXXXXXXXXXX
MAIL_ENCRYPTION=null
我想我可以在这里解决您的问题。您需要做的是严格设置以符合 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', 'username@gmail.com'),
'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 更改为以下内容;
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abdulkabirojulari@gmail.com
MAIL_PASSWORD=gjcltiocmmqoutfi
MAIL_ENCRYPTION=tls
MAIL_ENCRYPTION=tls非常必要,需要添加到.env文件中