【问题标题】:error Message: Expected response code 220 but got an empty response" with exception "Swift_TransportException",错误消息:预期响应代码 220,但得到一个空响应”,异常“Swift_TransportException”,
【发布时间】:2020-09-08 01:08:38
【问题描述】:

我正在按照教程在enter link description here 上使用护照身份验证构建 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 [
            //
        ];
    }
}

我也做过,两种身份验证方式 Mail.php

返回 [

'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

【问题讨论】:

  • .env 中进行任何更改后,运行 php artisan cache:clear 和 php artisan config:cache` 并重试。
  • 是的,我都做到了
  • 您是否尝试过 2-verification 并确保您配置了将在 .env 文件中使用的应用密码?
  • 是的,我做到了,2 向验证和应用密码

标签: laravel laravel-passport


【解决方案1】:

我想我可以在这里解决您的问题。你需要做的是做一个严格的设置以符合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文件中

【讨论】:

  • 非常感谢...这节省了我的时间。它就像一个魅力。
猜你喜欢
  • 2017-08-03
  • 2015-12-18
  • 2016-05-28
  • 2017-08-29
  • 1970-01-01
  • 2017-01-15
  • 2019-08-12
  • 1970-01-01
相关资源
最近更新 更多