Email – Simple Mail Facades – Laravel

In this example, one can send email using Mail facades.

Mail facades has 3 parameters

  • first parameter is for email view template to be used
  • second one is array of data to be send over template
  • closure eg. function($message) use() { } – in case need some modification over to, from, cc, bcc and attachment
// Must use 

use Illuminate\Support\Facades\Mail;


Mail::send('email.template',$data,function($message) use (
     $sender_name,
     $sender_email,
     $subject,
     $receiver_email,
     $receiver_name
    
 ){
     $message->to($receiver_email,$receiver_name)->subject($subject);
     $message->from('noreply@benera.com.au','Benera Contact Form');
     // $message->cc('cc@gmail.com');
     // $message->bcc('bcc@gmail.com');
     // $message->attachment('path to attach','name');
 });

use() – usefull when some data is need to pass inside closure.

Leave a Reply

Your email address will not be published. Required fields are marked *