Testing Mails Using The Command Line

Sometimes you might need to test Laravel mails using the command line, to see if they are being sent/received, use this method to simplify testing.

I will often use Tinkerwell and HELO for this but you can also use php artisan tinker and your regular email client.

Simply paste in the following snippet and update the email address to send the email:

Mail::raw('Test Mail', function($msg) {
    $msg->to('email@example.com')->subject('Test Mail');

If you are on PHP 7.4 +, you can simplify the above using short arrow functions:

Mail::raw('Test Mail', fn($msg) => $msg->to('email@example.com')->subject('Test Mail'));

After running the above snippet you will receive an email if everything has worked correctly: