I have a XAMP stack with a laravel 5.8 application running in localhost.
I am trying to send mails from application and want to use the default PHP mail function. I am assuming this does not need a SMTP server to send mails.
I have followed laravel documentation and this SO post How to configure Laravel mail.php to use built-in mail function?.
I have configured the sendmail as below
MAIL_DRIVER=sendmail
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'
Below is my code
try {
$users = \DB::select('SELECT * from laravel.users where DATEDIFF(end_date,CURRENT_DATE) > 10');
foreach($users as $user){
echo "\n $user->name";
}
\Mail::send('emails.reminder', ['users' => $users], function ($m) use ($user) {
$m->from('saurav.sarkar@mycompany.com', 'Your Monthly report');
$m->to('saurav.sarkar1@gmail.com')->subject('Your Reminder!');
});
}
catch (Exception $e){
echo 'Message: ' . $e->getMessage();
}
}
I can see that there are no runtime errors in my code but i don't get the mails consistently in in my inbox. The echo statement above the mail code is printed properly.
My emails.reminder blade template is a very basic view code.
I have seen the mails coming once but don't see it coming now. So, it has been quite an inconsistent behaviour.
Best Regards,
Saurav