如何在laravel 5中使用html模板发送电子邮件?

eivgtgni  于 2022-11-18  发布在  其他
关注(0)|答案(5)|浏览(187)

我想尝试简单的电子邮件发送喜欢在php,但我得到基于模板的电子邮件发送在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);`

但我想得到基于模板的身体html传递$消息喜欢

$body = $this->load-
 >view('admin/email_template/test_template',$data,TRUE);
 $this->email->message($body);
 $this->email->send();
2ekbmq32

2ekbmq321#

使用Mail::这样发送

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

并创建view.blade.php,用laravel blade编写。

pdtvr36n

pdtvr36n2#

使用make命令创建Mailable类

php artisan make:mail

然后在handle方法中编写代码

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

emails.complaint-reply.blade.php文件中写下您的HTML模板

xe55xuns

xe55xuns3#

我认为Mail::raw是您需要的:

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

0yg35tkg

0yg35tkg4#

use Illuminate\Support\Facades\Mail;

Mail::send('email.relatorlead', ['data' => $message], function ($m) use ($message) {
    $m->from('no-reply@twostructureshomes.com', 'Two Structures Homes');
    $m->to('nikunj@whitelabeliq.com');
    $m->subject('Realtor Registration Lead From ' . $message['firstname']);
});
btqmn9zl

btqmn9zl5#

看看这段代码,它一定会对你有所帮助。

<?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);
?>

相关问题