Send test mails from Terminal in Laravel
**Want to test your SMTP connection? And don't have time to write code? **
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('myawesomeemail@domain.com')->subject('Testing mails');
});
Happy laravel hacking,
Enjoy…!!!
I hope someone will get benefited with this article.
Sending mail with attachment using laravel and mailtrap.io