How to send test mail in Laravel via Terminal/Tinker

Just a small piece of code to test your mail settings and fire a test mail right from your terminal. I needed this when changing configuration in .env file to check different settings. But everytime changing setting and then running your piece of code which sends mail is kind of boring and lengthy. Instead just change config, fire a command is quick to test your settings. So I did it via Tinker in terminal. 

Laravel ships with very handy utility Tinker. From which we can play around with our application.

Go to your application’s root in Terminal or Command prompt. Fire below command

php artisan tinker

This will give you Tinker prompt. Now copy and paste below command in your tinker prompt. Don’t forget to change email address.

Mail::send('welcome', [], function($message) { $message->to('[email protected]')->subject('Testing mails '); });

Happy laravel hacking,

Enjoy…!!!

Shyam has written 29 articles

Shyam is senior full stack developer, who loves to explore new technologies and work on them. He's passionate about coding so can code 24/7. He uses PHP as a backend programming language.

He knows Laravel, MySQL, AngularJS, ReactJS, Redis, Kubernetes, Git, CodeIgniter, PHP, MVC pattern, Lodash, jQuery, VanilaJS, Teamcity and many other technologies and tools.

Shyam writes notes and hacks on his blog (https://shyammakwana.me). In spare time he can be found @ StackOverflow or crafting any new open source application.

Passionate Programmer and Meditator #PERIOD.