Testing Mails Using The Command Line

• 34 sec read • Share

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

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:

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

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

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

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

A test email sent using the code snippet.
A test email sent using the code snippet.

Join my mailing list.

Receive my latest content by email. No spam, ever.