Quick and easy way to test sending email on Laravel
This post provides a quick and easy way to test sending email on Laravel. All of the code required is contained in a route. The route that I set up allows you to sepcify the email address when testing the send mail functionality of your Laravel application.
This is only intended for a local development. This code should never be used in produciton!
Copy the code below into your web.php file within the /routes/
folder of your Laravel application.
If you visit the url of your Laravel application, with an email address, In this case we are using http://app.com
and we visit the page /emailtest/
with the email address test@test.com
, this looks like the following: http://app.com/emailtest/test@test.com
When this url is visited, it will display the current settings for the email send config along with sending an email to the test@test.com
email address.
/**
* testing only
* http://app.com/emailtest/test@test.com
*/
Route::get('/emailtest/{address}', function ($address) {
print_r( \Config::get('mail.mailers') );
$data = array('address' => $address);
Mail::raw('Hi, welcome ', function ($message) use ($data){
$message->to($data['address'])
->subject('test email');
});
return 'EmailSent';
});
This work was conducted as part of the development of Clinical Imaging Review System (CIRS).