laravel - sending email
ReportLaravel 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.
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