Home How to Send email with html templates in laravel 5?
Reply: 4

How to Send email with html templates in laravel 5?

Rajdip69869
1#
Rajdip69869 Published in 2018-01-10 06:20:37Z

i want to try simple email sent like in php but i get templates based email sending in Laravel 5 ??

`$to      = Session::get('email');
 $subject = 'Order confirmation';
 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
 $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
 $headers .= "From: Test <rajdipvekriya1992@gmail.com>"; 
 $message = 'test body';
 mail($to, $subject, $message, $headers);`

but i want get templates based body html pass $message like to

 $body = $this->load-
 >view('admin/email_template/test_template',$data,TRUE);
 $this->email->message($body);
 $this->email->send();
Yogesh Paliyal
2#
Yogesh Paliyal Reply to 2018-01-10 07:18:04Z

have a look to this code, this will surely help you.

<?php
   $to = "somebody@example.com";
   $subject = "My subject";
   $txt = "Hello world!";
   $headers = "From: webmaster@example.com" . "\r\n" .
   "CC: somebodyelse@example.com";
   mail($to,$subject,$txt,$headers);
?> 
Mahdi Younesi
3#
Mahdi Younesi Reply to 2018-01-10 06:27:37Z

create a Mailable class with make command

php artisan make:mail

then write your code in handle method

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
  return $this->view('emails.complaint-reply')
        ->subject('Cotint Group')
        ->with(['complaint'=>$this->complaint]);
}

And in emails.complaint-reply.blade.php file write down your HTML template

bruddah
4#
bruddah Reply to 2018-01-10 06:52:21Z

I think Mail::raw is what you need:

Mail::raw('Text to e-mail', function($message)
{
    $message->from('us@example.com', 'Laravel');
    $message->to('foo@example.com')->cc('bar@example.com');
});

https://laravel.com/docs/5.0/mail

Saly
5#
Saly Reply to 2018-01-10 07:19:47Z

Use Mail::send like this

\Mail::send('view', $data, function ($message)
{
    $message->subject('Email Subject');
    $message->from('acb@example.com');
    $message->to('xyz@example.com');
});

and create view.blade.php, write in laravel blade.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305174 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO