26th
October
2016
How to test email sending in Laravel 5.3 using artisan tinker
I’m building a Laravel app and ran into an error when trying to send mail but wasn’t getting an error back since the request was posted through ajax. If you’re trying to troubleshoot it, artisan tinker app is very useful to get more information on the error.
Fire up terminal/command line and run:
php artisan tinker
and then run the following snippet:
\Mail::raw('hello world', function($message) {
$message->subject('Testing email')->to('test@example.org');
});
You should either see a success/null message if everything was correct, or an error with details on what went wrong.
The error I encountered required configuring 2FA in Gmail or you can choose setting the insecure app option up to send through Gmail for testing.