laravel - sending email

Report
Question
714 views

Laravel uses free feature-rich library SwiftMailer to send emails. Using the library function, we can easily send emails without too many hassles. The e-mail templates are loaded in the same way as views, which means you can use the Blade syntax and inject data into your templates.

Please explain why do you think this question should be reported?

Report Cancel

In .env

MAIL_DRIVER = smtp MAIL_HOST = smtp.gmail.com MAIL_PORT = 587 MAIL_USERNAME = your-gmail-username MAIL_PASSWORD = your-application-specific-password MAIL_ENCRYPTION = tls;

for basic mail

public function basic_email()

{

$data = array('name'=>"Virat Gandhi");

Mail::send(['text'=>'mail'], $data, function($message) {

$message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel Basic Testing Mail');

$message->from('xyz@gmail.com','Virat Gandhi'); });

echo "Basic Email Sent. Check your inbox.";

for html mail

public function html_email()

{

$data = array('name'=>"Virat Gandhi");

Mail::send('mail', $data, function($message) { $message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel HTML Testing Mail');

$message->from('xyz@gmail.com','Virat Gandhi'); });

echo "HTML Email Sent. Check your inbox.";

}

for attachment mail

public function attachment_email()

{

$data = array('name'=>"Virat Gandhi");

Mail::send('mail', $data, function($message) { $message->to('abc@gmail.com', 'Tutorials Point')->subject ('Laravel Testing Mail with Attachment');

$message->attach('C:\laravel-master\laravel\public\uploads\image.png');

$message->attach('C:\laravel-master\laravel\public\uploads\test.txt');

$message->from('xyz@gmail.com','Virat Gandhi'); });

echo "Email Sent with attachment. Check your inbox.";

}

Thread Reply

Leave an comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>