Cannot send password reset link from laravel 5.8 - php

As titled, I cannot get Laravel to send password reset emails. I am using the "out of the box" auth command to handle the password reset and I put in all the details from the email account I set up in cpanel. Laravel will authenticate the details ok and will tell me the reset link has been sent ok but the email hasn't been sent from the mail account and it doesn't show in the target email either. don't know what I've done wrong but here's my code section from the .env file:
MAIL_DRIVER=smtp
MAIL_HOST=n3plcpnl0067.prod.ams3.secureserver.net
MAIL_PORT=465
MAIL_USERNAME=**account address**
MAIL_PASSWORD=**acount password**
MAIL_ENCRYPTION=ssl
and from the mail.php file:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'n3plcpnl0067.prod.ams3.secureserver.net'),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Password reset'),
],
It works fine when I use the dummy account on mailtrap, just not with the email set up in cpanel for my hosting

Related

Email doesn't send from Laravel to Webmail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I can't send email from my Laravel live project to an webmail account.
I have configured all possible files to send email.
config/mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'sg2plcpnl0003.prod.sin2.secureserver.net '),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#ezmoverandrental.com'),
'name' => env('MAIL_FROM_NAME', 'Test'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'sendmail' => '/usr/sbin/sendmail -bs',
.env
MAIL_DRIVER=mail //also tried with 'sendmail' and 'mail'
MAIL_HOST=sg2plcpnl0003.prod.sin2.secureserver.net
MAIL_PORT=587 //also tried with '645'
MAIL_USERNAME=info#ezmoverandrental.com
MAIL_PASSWORD='webmail_password'
MAIL_ENCRYPTION=ssl //also tried with 'tls'
Another interesting part is there is no error shows in my 'storage/log' file. Just I see in console that it returns '0'.
Here is the send mail method
public function sendMail($emailDataArray)
{
Mail::send('mail', $emailDataArray, function($message) use ($emailDataArray)
{
$message->to('info#ezmoverandrental.com')->subject('New Online Estimate');
$message->from('info#ezmoverandrental.com');
});
return;
}
That means my project is connected successfully with the webmail but unfortunately mail doesn't send.
I have already tried with 'sendmail' and 'mail' drive
Anybody Help Please.
Your Method is Ok just Double check the values and make sure mail port,Drivers and the ENCRYPTION values are the same in the env and mail.php are same.
.env file
`MAIL_PORT=587
MAIL_DRIVER=smtp
MAIL_ENCRYPTION=tls`
mail.php file
`'port' => env('MAIL_PORT', 587)
'driver' => env('MAIL_DRIVER', 'smtp')
'encryption' => env('MAIL_ENCRYPTION', 'tls') `
It seems your method is okay. Suggest you double check your mail host .env.
You could use Mail Gun or Mailtrap
**Mailtrap .env configuartion**
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your mailtrap username hashcode
MAIL_PASSWORD=your mailtrap password hashcode

Unable to send password reset email using Laravel built in mail

I have been trying to get emails to send from Laravel for the past day without success. I have been testing locally using homestead and on a live linux server environment with no luck.
I have removed email settings from the .env file. and directly added the settings in my config/mail file.
so far I have tried office 365 settings, gmail and finally maligun, none of which send an email.
my settings are below.
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'postmaster#sandbox********099b827475b585029.mailgun.org'),
'name' => env('MAIL_FROM_NAME', 'Test account'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('postmaster#sandbox****************099b827475b585029.mailgun.org'),
'password' => env('********************'),
I complete the password reset process via password/reset and it says the password reset link was sent successfully but it is never sent, the mailgun logs confirm no email was sent, the token is updated in the password_reset table
I ssh'd onto homestead and tested sending a email via mailgun using curl and this works.
if I set mail driver to SMTP I still get the same issue.
when setting the drive to 'log' the log files shows the email template etc.
any help would be appreciated.
thanks
What environment you working with? Local or production?
What kind of email you're using? Gmail or testing mail such as mailtrap?
If gmail did you active smtp from settings? Please provide more information.
Update:
let us test other ways to see if it makes any differences:
Go to your routes file web.php and comment this:
// Auth::routes();
Now add following routes:
// Authentication routes
Route::get('/login',['as'=>'login', 'uses' => 'Auth\LoginController#showLoginForm']);
Route::post('/login', ['uses'=>'Auth\LoginController#login']);
Route::get('/logout',['as'=>'logout', 'uses'=>'Auth\LoginController#logout']);
Route::get('/register', ['as' => 'register', 'uses' => 'Auth\RegisterController#showRegisterForm']);
Route::post('password/email', ['as'=>'password.email', 'uses'=>'Auth\ForgotPasswordController#sendResetLinkEmail']);
Route::get('password/reset', ['as'=>'password.request', 'uses'=>'Auth\ForgotPasswordController#showLinkRequestForm']);
Route::post('password/reset', ['as'=>'password.request', 'uses'=>'Auth\ResetPasswordController#reset']);
Route::get('password/reset/{token}', ['as'=>'password.reset', 'uses'=>'Auth\ResetPasswordController#showResetForm']);
Route::post('logout', ['as'=>'logout', 'uses'=>'Auth\LoginController#logout']);
Try and see if it works or not.

Using mailgun on laravel 5.2 - failed to authenticate my sandbox account

I'm using Laravel 5.2 that has mailgun integrated. Was trying to send out email via SMTP but couldn't succeed because of the error:
Failed to authenticate on SMTP server with username
"postmaster#sandboxe56d93c917b144e98a4f07d1dbf2683a.mailgun.org" using
3 possible authenticators
I'm developing the app on my localhost with virtual host set up (i.e. app.dev.local) so I have to use the sandbox account to do all the testing.
These are the laravel's config/mail.php:
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => 'postmaster#sandboxe56d93c917b144e98a4f07d1dbf2xxxx.mailgun.org',
'password' => 'mypassword'
service.php's configurations
'mailgun' => [
'domain' => 'sandboxe56d93c917b144e98a4f07d1dbf2xxxx.mailgun.org',
'secret' => 'key-63sztbx99h-qdhp7j3-gp6346jsxxxx',
],
Everything looks good as I copied directly from my mailgun dashboard for the sandbox account, but the app still can't send out email due to failed authentication.
Does anybody know what is happening here?
Try with port 2525 maybe? You can edit it in the config/mail.php file where 587 is currently or through setting it in your .env file:
MAIL_PORT=2525
small correction
Check MAIL_DRIVER, MAIL_HOST, MAIL_PORT values in .env file. If you have this parameters set in .env file, function env call will take the values from that localization.

Swift_TransportException in Laravel 5.2 mail sending

I am trying to send mail for my laravel app from a gmail account with Allow less secure apps: ON and 2-Step Verification OFF
.env part for mail:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=library#gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=ssl
config/mail.php:
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'library#gmail.com', 'name' => 'Admin'],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('library#gmail.com'),
'password' => env('********'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', false),
First I tried using 'encryption' => env('MAIL_ENCRYPTION','tls'). But got the following error message:
ERROR: exception 'Swift_TransportException' with message 'Expected
response code 250 but got code "530", with message "530-5.5.1
Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257
z3sm16020712par.17 - gsmtp"' in
/home/shafi/Projects/Lib/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
I visited https://support.google.com/mail/answer/14257 and found everything is at the recommended state.
After this I used 'encryption' => env('MAIL_ENCRYPTION','ssl') but this time the same ERROR.
What should I do to fix the error? What am I missing?
Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.
Note: If this still didn't help then retry the process couple of more times and wait then try to send the email from your Laravel apps. This should resolve the issue.
Step 1: Revert your config/mail.php to original file. The config/mail.php should look like this
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'library#gmail.com', 'name' => 'Admin'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
Step 2: The .env file should be like
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=library#gmail.com
MAIL_PASSWORD=whateverisyourpassword
MAIL_ENCRYPTION=ssl
Port is 465 and not 587
Step 3: Test the below code by pasting in appropriate controller function
\Mail::raw('This is an test e-mail', function ($message) {
$message->to("someone#gmail.com", "someone");
$message->subject("hi checking");
$message->getSwiftMessage();
});
P.S: Never ever forget to stop and then again start the server by using php artisan serve every time if some change is made to .env file. If not then you may be sucked into The Labyrinth of Time.
For me, sending mail worked by just adding the correct info in the .env file like so:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_gmail_email
MAIL_PASSWORD=your_gmail_password
MAIL_ENCRYPTION=tls
Don't change anything in the mail.php file. You don't want your email credentials all over the place. The .env file was made to store all of this.
I also turned on access to "less secure apps" on that Gmail account.
And lastly, run: php artisan config:cache
Hopefully that helps.
I had the same problem previously, the root cause was I changed the mail.php file.
To send email with smtp.gmail.com, you just need to change the configuration in .env file and enable allow less secure apps. Don't change anything in the mail.php file.
I'd recommend you to take the time to read this :
https://phpnotebook.com/how-to-fix-swift_transportexception-530-in-laravel-5-7.html

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

I am trying to send a mail to my email-id. I have followed all the steps that might required to send a mail.
But it keeps on coming 2 errors
Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.#10060]
Maximum execution time of 30 seconds exceeded.
my controller is
public function contact()
{
Mail::send('clientinfo.contact',['name' => 'shweta'],function($message){
$message->to('myemail#gmail.com','Some Name')->subject('Welcome!')->from('otheremail#example.com');
});
mail.php file :
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'someone#example.com', 'name' => 'Some One Sender'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Please help me through this.
Make sure you install Guzzle to your project by adding the following line to your composer.json file:
"guzzlehttp/guzzle": "~5.3|~6.0"
and editing your .env file with real email-id and password. Also, enable, less secure apps for that email-id as told by #Bharat Geleda
then your above code will run properly.
This is what I did.
I enabled two step verification on may gmail account
created separate apps password for my app here (screenshot below) (https://security.google.com/settings/security/apppasswords)
I that password into my laravel .env file and it worked.
screenshot
just select "Other(custom name)" on the "select app" and it will generate a password for you.
Use the MAIL_PORT=587 instead of the default mail_port in your .env file.

Categories