Payne
Payne

Reputation: 543

error Message: Expected response code 220 but got an empty response" with exception "Swift_TransportException",

enter image description hereI am following a tutorial to build an API using passport authentication on enter link description here I have followed the part 1 and walking through the part 2 with account confirmation and notifications but 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:clear but the same error is displayed.

<?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

<?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

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=XXXXXXXXXXXXXXX
MAIL_ENCRYPTION=null

Upvotes: 4

Views: 16251

Answers (1)

Abdulkabir Ojulari
Abdulkabir Ojulari

Reputation: 1467

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

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;

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=gjcltiocmmqoutfi
MAIL_ENCRYPTION=tls

MAIL_ENCRYPTION=tls is very essential and needs to be added to the .env file

Upvotes: 4

Related Questions