Laravel Mailtrap Localhost - Error sending mail - laravel

I would like to send a emai to a gmail address using Laravel 5.4 and Mailtrap while working on my localhost:8888.
I've got this error Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
I tried
Using different port
php artisan config:clear
What is wrong ?
.env
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=465
MAIL_USERNAME=xxxxx
MAIL_PASSWORD=xxxxx
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=example#example.com
MAIL_FROM_NAME=Leo
config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'username' => env('xxxxx'),
'password' => env('xxxxx'),

I needed to change
'username' => env('xxxxx'),
'password' => env('xxxxx'),
to
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

The below code (in .env file) solved my problem in sending verification
email - Laravel 5.7. No need to change in config/mail.php
MAIL_DRIVER=smtp
MAIL_HOST=mail.somedomain.org
MAIL_PORT=465
MAIL_USERNAME=someone#somedomain.org
MAIL_PASSWORD=your_pwd
MAIL_ENCRYPTION=SSL
MAIL_FROM_ADDRESS=someone#somedomain.org
MAIL_FROM_NAME=SenderName

Related

Laravel 8: Connection could not be established with host smtp.gmail.com

I'm trying to send a simple email from my laravel 8 app using Google SMTP server, but it doesn't work, I'm getting this error:
Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): SSL:
or
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
I found many SO post regarding this issue but none of them worked for me, here's a list of what I have tried:
Enabling less secure apps in the google account
using ports 465 and 587
Using smtp.googlemail.com and smtp.gmail.com
Using MAIL_ENCRYPTION=tls and ssl
Changing 'stmp' to 'sendmail'
Blocking switmailer's ssl constraint
Is there something else I can try?
Here's my mail configuration, although I've tried many versions of it:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=address#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
I had the same problem, I just disabled my antivirus (Avast / windows 10) and its work.
Try this and add the extra auth mode env variable
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=direction#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
MAIL_AUTH_MODE=login
Now go to config/mail.php
and change
'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,
],
to
'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' => env('MAIL_AUTH_MODE'),
],
Finally, it was a problem with Windows. I found some posts pointing that windows just can't execute some mail services. I tried the exact same code in a computer with Ubuntu and it worked at first try.

Failed to authenticate on SMTP server with username "hello#gmail.com" using 3 possible authenticators

When i run the code i got error "Failed to authenticate on SMTP server with username "hello#gmail.com" using 3 possible authenticators. Authenticator CRAM-MD5 returned Expected response code 235 but got code "535", with message "535 5.7.0 Invalid login or password ". Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response."
config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'Hello'),
],
'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 file is
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=hello#gmail.com
MAIL_PASSWORD=****
MAIL_ENCRYPTION=tls
do it like this in your env:
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***
MAIL_PASSWORD=***
MAIL_ENCRYPTION=tls
Turn on Less secure app access
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=yourmail#gmail.com
MAIL_PASSWORD=yourgmailpassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=yourmail#gmail.com
Each port uses a different protocol, errors like the one you had can be caused by the protocol mismatch.
Change your SMTP port to 25 or 465 or 587 or 2525 in .env file,
Save and restart the server by php artisan serve.

Swift_TransportException Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted

I'm trying to send email using laravel 5.4 but I'm getting this error.
I try to enable less secure application for my account but nothing seems to work for me. this is my code:
use Mail;
class UserController extends Controller{
public function register(Request $request)
{
$inputs=$request->all();
$data=$inputs;
Mail::send('mail.ajout', $data, function($message) use ($data)
{
$message->from($data['email']);
$message->subject("Nouvelle inscription");
$message->to('myaccount#gmail.com');
});
}
}
my env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_USERNAME= myacount#gmail.com
MAIL_PASSWORD= mypwd
MAIL_ENCRYPTION=tls
mail.php
<?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', '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'),
],
],
];
any help please ,thanks in advance
Is there space in after .env variable = ? Then just remove it takes space as a character.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_USERNAME=myacount#gmail.com
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=tls
After changing .env clear your config and restart your server.
php artisan config:clear
php artisan serve

Swift_TransportException in StreamBuffer.php line 268:

When I try to send an email from my laravel site I get this error
Swift_TransportException in StreamBuffer.php line 268: Connection could not be established with host lin01.hkdns.co.za [ #0]
all my details is right. my env
MAIL_DRIVER=smtp
MAIL_HOST=lin01.hkdns.co.za
MAIL_PORT=465
MAIL_USERNAME=info#mysite.co.za
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
In my mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#mysite.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'),
],
],
Did I miss something or is this a problem on my server?
Sometime it's possible to be "cache" in the laravel.
Use this command and try again:
php artisan config:clear
If not work, try to restart you xampp.
Another option to check if the problem is with your host or your configuration is to use a Gmail server to send a test email.
Puts this in your .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
Create or use any gmail account and enable the less secure apps more information here
first login to your gmail account and under My account > Sign In And
Security > Sign In to google, enable two step verification, then you
can generate app password, and you can use that app password in .env
file.
Your .env file will then look something like this
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
Don't forget to run php artisan config:cache after you make changes in
your .env file (or restart your server).
Source here

Laravel: send password reset link

Problem. When I try to send password reset link with Laravel (v.5.2), i get this error message:
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 220 but got code "", with message ""
How can I fix this?
.env.
MAIL_DRIVER=smtp
MAIL_HOST=send.one.com
MAIL_PORT=465
MAIL_USERNAME=info#myemail.se
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'send.one.com'),
'port' => env('MAIL_PORT', 465),
'from' => ['address' => 'info#myemail.se', 'name' => 'donotreply'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
Other info. I have my project on a shared host site called one.com. The project is quite small, and not much is changed from the Laravel installation. I uploaded it by copying it into the domain, and changed a few settings.
It could be many settings, my current suspicion would be the MAIL_ENCRYPTION=null. Have you tried setting it to MAIL_ENCRYPTION=ssl? Since it's port 465, it might be neither null or tls (the env() fallback) .

Resources