Swift_TransportException in AbstractSmtpTransport.php line 383: in Laravel - laravel

I'm trying to create a contact form using laravel 5.4 and I added my server email details to the .env and the mail.php but I'm getting this error
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "421", with message "421 Unexpected failure, please try later
"
If I try this and I use mailtrap it works fine.
This is my mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#website.co.za'),
'name' => env('MAIL_FROM_NAME', 'Info'),
],
'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'),
],
],
];
My .env file
MAIL_DRIVER=smtp
MAIL_HOST=hosting.com
MAIL_PORT=587
MAIL_USERNAME=info#website.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=

Check the config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', ''),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', ''),
'password' => env('MAIL_PASSWORD', ''),
'sendmail' => '/usr/sbin/sendmail -bs',
];
Make sure the .env file has the following
MAIL_DRIVER=smtp
MAIL_HOST=hosting website
MAIL_PORT=587
MAIL_USERNAME=your username
MAIL_PASSWORD=your password
MAIL_ENCRYPTION=tls
Also clear the config cache
php artisan config:cache

Related

How to set second mail env configurations and make use of it?

I have this env variables:
MAIL_MAILER=smtp
MAIL_HOST=smtp.zoho.com
MAIL_PORT=587
MAIL_USERNAME=accounts#mozcoders.com
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=accounts#mozcoders.com
MAIL_FROM_NAME="${APP_NAME}"
INFO_MAIL_MAILER=smtp
INFO_MAIL_HOST=smtp.zoho.com
INFO_MAIL_PORT=587
INFO_MAIL_USERNAME=info#mozcoders.com
INFO_MAIL_PASSWORD=xxxxxxxxxx
INFO_MAIL_ENCRYPTION=tls
INFO_MAIL_FROM_ADDRESS=info#mozcoders.com
And this mail mailers:
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'info' => [
'transport' => 'smtp',
'host' => env('INFO_MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('INFO_MAIL_PORT', 587),
'encryption' => env('INFO_MAIL_ENCRYPTION', 'tls'),
'username' => env('INFO_MAIL_USERNAME'),
'password' => env('INFO_MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
When I send email using the default configurations it works fine, but when I use the custom configurations it returns an error:
local.ERROR: Expected response code 250 but got code "553", with message "553 Relaying disallowed as default#mail.com
" {"userId":1,"exception":"[object] (Swift_TransportException(code: 553): Expected response code 250 but got code \"553\", with message \"553 Relaying disallowed as default#mail.com
\"
Here is the code from my Notification file:
return (new MailMessage)
->mailer('info')
->subject('Some subject')
->markdown('mail.failure', ['data' => $this->failureData]);
I was able to achieve what i wanted by moving this array:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
to desired mailers array:
...
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],
'info' => [
'transport' => 'smtp',
'host' => env('INFO_MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('INFO_MAIL_PORT', 587),
'encryption' => env('INFO_MAIL_ENCRYPTION', 'tls'),
'username' => env('INFO_MAIL_USERNAME'),
'password' => env('INFO_MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'from' => [
'address' => env('INFO_MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required "

I got stuck on this error. I am trying to configure SMTP mail on laravel.
I have this issue when I want to send the password reset link:-
I found the reference but I have make change on 'host' and 'port'
'host' => env('MAIL_HOST', 'mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
but I still have the same issue .
My config/mail.php:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'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'),
],
],
];

Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first.

I Used Laravel Authentication,And in Reset Password I Want to send Reset Link to email.
My .env is here:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=MyPassword
MAIL_ENCRYPTION=null
And my 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', 'hanieasemi76#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'hanie'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
And Turn on 2-step verification of my gmail,But Now When I Want to send email I give this Error Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. r7-v6sm5414781wrn.83 - gsmtp
How I can fixet it?where is my problem?

Laravel 5.5 Expected response code 250 but got code "530"

I know it is a duplicate issue in StackOverFlow (Laravel SwiftMailer : Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required) however, I'm done all the remedies discussed there but still no luck. I'm using mailtrap.io using my GMail account. Here is the .env file and mail.php (under config):
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=XXXX
MAIL_PASSWORD=XXXX
MAIL_ENCRYPTION=tls
mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'niladriXXX#XXX.com'),
'name' => env('MAIL_FROM_NAME', 'Niladri Banerjee'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'sendmail' => '/usr/sbin/sendmail -t -i',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
After submitting the valid email from forgot password screen, it throws the following error:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required "
Please note: I have already ON 'Allow less secure apps' from "Sign-in & security" from my GMail.
Seeking your help.
PS: I'm running the project in localhost.
I' may suggest you use this as well, it worked for me,
Please Note if you're using Gmail: create a gmail app password, but be sure to your 2 Step verification set up, from sign in and securiity, the following link: https://myaccount.google.com/apppasswords to setup app password,
use that and follow procedure 2 after this return to set up gmail with smtp.
please note: code down below are for mail.php file
(do not forget to use: php artisan config:cache)
after changes to .env file as well
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'lxxxx#xxxx.com'),
'name' => env('MAIL_FROM_NAME', 'myMail'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),//this setting in .env only leave as is here
'password' => env('MAIL_PASSWORD'),//this setting in .env only leave as is here
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
//procedure 2 for gmail
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'lxxxx#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'myMail'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),//this setting in .env only leave as is here
'password' => env('MAIL_PASSWORD'),//this setting in .env only (use app password you created for gmail and PLEASE leave as is here
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Hope it helps.
Kind regards
add MAIL_FROM=mailtrap.io username to your .env file
and php artisan config:cache.
if you see, mail.php needs this for authentication

Laravel 5.5 and mailgun

I have been trying to send emails from my laravel app with mailgun but cant get it to work.
.env
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=(Default SMTP Login from mailgun)
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS= hello#****.*****.me
MAIL_FROM_NAME= Me
MAILGUN_DOMAIN=*****.*****.me
MAILGUN_SECRET=key-10*****************************f
mail.php
return [
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', '*****.******.me'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#*****.******.me'),
'name' => env('MAIL_FROM_NAME', 'Me'),
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('postmaster#*****.******.me'),
'password' => env('************'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
services.php
'mailgun' => [
'domain' => env('*****.******.me'),
'secret' => env('key-1******************************f'),
],
Using this url to test
Route::get('/send_test_email', function(){
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{
$message->to('finchy70#gmail.com');
});
});
No errors but no emails sent. Also no activity on my mailgun dashboard.
All my mailgun DNS settings are verified for my domain.
Can anyone see what I'm doing wrong?
Looks like you're using the value instead of the name in the config for username, password, domain, and secret. Should be
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
And
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],

Resources