Laravel 6 send mail - laravel

I have an issue with authentication while sending mail with Laravel smtp driver.
.env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=account#gmail.com
MAIL_FROM_ADDRESS=account#gmail.com
MAIL_PASSWORD=app_password
MAIL_ENCRYPTION=tls
It gives the following error:
"530-5.7.0 Authentication Required. "
2-Factor auth is enabled and app password is used;
Also tried with SSL on 465, same error;
Config is flushed every time .env is changed;
Everything in config/mail corresponds to .env;
SO all typical solutions are not working. What else may cause this problem?
I have also tried using smtp.vivaldi.net with vivaldi account, it authenticates, but gives an error:
"no valid recipients"
while recipient email is surely valid, which is also strange for me.

I've stumbled across this multiple times already, hence I do not remember the exact error-message which I received but here is my assumption.
Google has an option called "less secure apps" which you need to enable in order to send directly mails through their SMTP interface. Can you check if this flag is disabled and try to enable it?
https://support.google.com/a/answer/6260879
In addition to that google is slowly deprecating this feature. Starting from Mid 2020 you'll be not able to enable this flag anymore and they will completely remove this in 2021.
Reference: https://gsuiteupdates.googleblog.com/2019/12/less-secure-apps-oauth-google-username-password-incorrect.html

Firstly, you need to setup 2 step verification here google security.
An App Password link will appear and you can get your App Password to insert into below "MAIL_PASSWORD". More info on getting App Password here
MAIL_DRIVER=smtp
MAIL_FROM_ADDRESS=noreply#talhaf.com
MAIL_FROM_NAME=System
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=YOUR_GMAIL#gmail.com
MAIL_PASSWORD=YOUR_GMAIL_CREATED_APP_PASSWORD
MAIL_ENCRYPTION=tls
Don't forget to clear cache with :
php artisan config:cache

Problem was that I messed up with config/mail.php.
I wrote
'username' => env('email'),
'password' => env('app_password'),
Instead of
'username' => env('MAIL_USERNAME','email'),
'password' => env('MAIL_PASSWORD','app_password'),

Related

Error sending email using Gmail SMTP with Laravel

I'm trying to send mails from my webserver using Laravel 6 like this:
Mail::send('feedback', ['email' => $email, 'text' => $text], function($message) use ($receiver)
{
$message->to($receiver, 'The receiver')->subject('New Feedback');
});
I added my login information into my .env file according to this page from google:
https://support.google.com/mail/answer/7126229?hl=de
my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxx#gmail.com
MAIL_PASSWORD=my_gmail_login_password
MAIL_ENCRYPTION=tls
but I keep getting this error message:
Expected response code 250 but got code "530", with message "530-5.7.0 Authentication Required. Learn more at
530 5.7.0 https://support.google.com/mail/?p=WantAuthError
It looks like I would have used wrong credentials but I'm able to login with these credentials in gmail.
I also enabled insecure apps in my gmail settings.
I also tried to solve it by creating an app password and using it instead of my gmail password.
Nothing worked.
Does someone have an idea what I'm doing wrong?
when you want to send email from gmail you have to change some settings in gmail account.
Step 1: Configure your Google Account
Login to your Google Email Account and click on Google Account Button. This button is display when you click on the profile picture in your Gmail Dashboard as shown
Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.
I think this link is helpful to you
https://medium.com/#agavitalis/how-to-send-an-email-in-laravel-using-gmail-smtp-server-53d962f01a0c
I could solve it by changing
MAIL_DRIVER=smtp
to
MAIL_DRIVER=sendmail
now I don't get any errors logged and everything seems to be working fine, but the mails don't get delivered to the mail address where they should be.

having issues on sending email in laravel 5.8

I am having issues on sending email via notification. I tried accessing the mailbox using the credentials I put in .env, the credential is good I am able to access the inbox but if I run the command sending email is failed.
on my .env
MAIL_DRIVER=smtp
MAIL_HOST=myhost
MAIL_PORT=465
MAIL_USERNAME=this#isworkingemail.com
MAIL_PASSWORD=pWdisWorking
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=this#isworkingemail.com
MAIL_FROM_NAME='AFTSCredit'
my function via
public function via($notifiable)
{
return [TwilioChannel::class,'database','mail'];
// return [TwilioChannel::class,'database'];
}
any idea? plase help thank you in advance!
Your error says Authentication error. This is nothing to do with Laravel/PHP mailer.
Try one of these below:
Clear cache
Check if you have modified config file. Make sure your .env variables are being pointed in your config file
Check if your server allows outbound emails
Check if you have right credentials such as host name, username, password
If you need extra authentication to allow using smtp services like google. You will need to activate to allow to use less secure app.
Finally, but not the least
If your mail server password contains a # then you should quote the environment string since everything after # will be taken as comment (starting in Laravel 5.8)
put the port and host as follows
MAIL_PORT = 587
MAIL_HOST= smtp.gmail.com
and also in your gmail . Disable two authentication and enabled unsecured apps
and then it would be okkay

How to configure postfix and Laravel on same server

I am developping a complex website but when I try to deploy it I got an error whenever the website needs to send an email (for the email validation system, built-in with Laravel). The error I got is:
[ErrorException (E_NOTICE)] Undefined offset: 3
The exception seems to be thrown from /vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php.
The only changes I made to config/mail.php is to allow self-signed certificates for ssl. My .env file contains these lines:
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=myusername //match in real file
MAIL_PASSWORD=mypassword //match in real file
MAIL_FROM_ADDRESS=from#mydomain.stackoverflow
MAIL_FROM_NAME=MyAppName
MAIL_ENCRYPTION=tls
My mail server is on the same server (as you could guess with MAIL_HOST=localhost) and is running postfix with Dovecot. I'm also using a webmail app (roundcube) to use my mail server and it works fine (except for OpenDKIM which doesn't sign outcoming mails).
Do you have any idea where my problem can come from?
EDIT: It works with Mailtrap.io so the problems should come fromp the configuration but I don't know if it comes from my Postfix config or from my Laravel config
EDIT2: I still don't understand why but removing credentials works fine. It works with credentials but only if I remove the MAIL_ENCRYPTION option (setting it to null). So here is the working config I have:
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_FROM_ADDRESS=from#mydomain.stackoverflow
MAIL_FROM_NAME=MyAppName
MAIL_ENCRYPTION=tls

How to set up mailgun with laravel 5.7?

I am trying to set up mail sending with mailgun on my deployed laravel application. I am able to send email verification emails, but I can't send to my email. For example:
Notification::route('mail', 'admin#mywebsite.org')
->notify(new Feedback($user->email, $subject, $message));
When I was using mailtrap.io to test my mail sending it worked perfectly.
My .env file looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAILGUN_SECRET=key-<key>
MAIL_USERNAME=postmaster#sandbox<somenums>.mailgun.org
MAIL_PASSWORD=<mypass>
MAIL_ENCRYPTION=tls
When I try to send the email it brings this error: Expected response code 250 but got code "554", with message "554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings. "
welcome to SO.
Please have a deeper look at the Laravel official documentation where you can find everything you need to set up the mailgun driver.
Mailgun Driver
To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. Next, verify that your config/services.php configuration file contains the following options:
'mailgun' => [
'domain' => 'your-mailgun-domain',
'secret' => 'your-mailgun-key',
],
After updating your conf you have to change the MAIL_DRIVER env variable from smtp to mailgun. All the other settings for username, password and so on are not required.

Expected response code 235 but got code 535 laravel send email using office365 smtp

I want to send email using my office365 smtp credentials in laravel application. i have make changes in my .env file for email settings as below:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=info#***.com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls
while i am trying to send email i got error like
Failed to authenticate on SMTP server with username \"info#omoyyc.com\" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code \"535\", with message \"535 Incorrect authentication data\r\n\"
my email sending code is as below
Mail::send(array(), array(), function ($m) use ($templatecontent) {
$m->from('customerservice#****.com', 'TEST');
$m->to('test#gmail.com', 'Test')
->subject($templatecontent['subject'])
->setBody($templatecontent['content'], 'text/html');
});
Can anyone guide me what is the issue and how to solve this issue?
I don't know if the cause is the same as OP, but I got the same error. I fixed it by enclosing the password with double quotes.
I'm assuming that the parsing fails when the password contains special characters.
I had the same issue.
I used Gmail SMTP, with less secure apps enabled & 2-factor auth disabled, and nothing worked. And surprisingly as #jessij mentioned, setting the password in double-quotes worked.
Do below in .env file:
Replace: MAIL_PASSWORD=yourpassword
With: MAIL_PASSWORD="yourpassword"
my problem is same dude, but my problem has been solved to try it :
Go to https://myaccount.google.com/security#connectedapps
Take a look at Security menu -> Apps with account access menu.
You must turn the option "Allow less secure apps" ON.
If you already followed this step, try again your project. and if it still doesn't work, please continue this steps :
Visit https://accounts.google.com/UnlockCaptcha
Click continue button
Good Luck dude!
If your password contains special characters like "john##3398", put this in " ". Then clear your php artisan cache using
php artisan config:cache
Then start your php artisan serve.

Resources