Laravel

How to send emails in laravel?

Hi, In this tutorial I am going to explain how the laravel framework proving mailer concept to your website.

Laravel provides a clean, simple API over the popular SwiftMailer library. The mail configuration file is app/config/mail.php, and contains options allowing you to change your SMTP host, port, and credentials, as well as set a global from address for all messages delivered by the library. You may use any SMTP server you wish. If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file. A sendmail driver is also available.

How to call mail function in Controller :

 

$data and $user in an custom defined array, $data will pass the values into welcome.blade file.  You want to use array inside mail function means, you need to call use array like function($message) use ($user).

This function call welcome.blade file which is under views/emails/welcome.blade

My welcome.blade file :



If you are using TEIG file my welcome.twig file like:

There is possible to set send mail later.

This function will execute the mail function after 3600 seconds.

That’s all. Happy mail sending.

Thanks!. If you like this article please don;t forget to share and comment.