I use Windows 10, Laragon and Laravel Framework.
And I setup the default Auth by calling php artisan make:auth
The problem is when I try to use the Forgot Password component, the 'sendmail' does not work. After I click Send Password Reset Link
, nothing happened. And the Password Reset Link
does not sent to the Laragon's Mail Catcher
.
This is the configuration inside .env
MAIL_DRIVER=sendmail
MAIL_SENDMAIL="C:\laragon\bin\sendmail\sendmail.exe -bs"
And this is inside config/mail.php
'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs'),
Firstly, I was using custom username and password I got from my Cpanel hosting email account to setup laravel mail. It did not go through via the sendmail config or smtp config.
Reading up the doc i noticed laravel does extend the swift mailer class. I made my twick thus.
$user = User::find(1);
$text = (new WelcomeEmail($user))->render();
// Create the Transport
$transport = (new \Swift_SmtpTransport(env('MAIL_HOST'), 25))
->setUsername(env('MAIL_USERNAME'))
->setPassword(env('MAIL_PASSWORD'))
;
// Create the Mailer using your created Transport RFCValidation
$mailer = new \Swift_Mailer($transport);
// Create a message
$message = (new \Swift_Message('Happy to Have You Onboard'))
->setFrom([env('MAIL_FROM_ADDRESS') => env('MAIL_FROM_NAME')])
->setTo(['miracle@yahoo.com'])
->setBody($text , 'text/html')
;
$message->setReadReceiptTo(env('MAIL_FROM_ADDRESS'));
// Send the message
$result = $mailer->send($message);
Now the
"new WelcomeEmail"
is a Laravel mailable that bundles the view for the mail. You can brilliantly create your own mail class out of this above code to make your code tiny and extendable.