Send mail in laravel 10

502 0 0 0

Last Updated : 2024-04-30 20:21:47

Here is a sample simple code to send email message in laravel

$data = array('name'=>'Roger Jackson', "date" => "01/01/2020", "myName"=>"Jack Hamelton"); //These array keys can be accessed directly in the blade template as variables/

Mail::send('emails.testEmail', $data, function($message) {
$message->to(config('app.NotificationEmailAddress'), config('app.NotificationEmailName'))
->subject('Test Email #'. rand(1, 1000));
});

Now create a blade template in resources/views/mail folder


Hello, 

This is a test message

<p>

{{ $myName }}
If you haven't asked for this request, please ignore this message completely.

Thank you

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .