Level 42
If you configured your .env for email, you can try below sample:
Route::get('/mail', function () {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('welcome', $data, function ($message) {
$message->from('FROMEMAIL_ADDRESS', 'Learning Laravel');
$message->to('TOEMAIL_ADDRESS')->subject('Learning Laravel test email');
});
if (Mail::failures()) {
print_r(Mail::failures());
} else {
return "Your email has been sent successfully";
}
});
.env something like:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=YOUR_GMAIL_ADDRESS
MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=tls
NOTE: Replace FROMEMAIL_ADDRESS and TOEMAIL_ADDRESS with actual one
2 likes