我想尝试在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);`
但我希望获取基于body html的模板传递$ message消息
$body = $this->load-
>view('admin/email_template/test_template',$data,TRUE);
$this->email->message($body);
$this->email->send();
答案 0 :(得分:0)
使用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模板
答案 1 :(得分:0)
我认为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');
});
答案 2 :(得分:0)
使用Mail :: send like this
\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编写。
答案 3 :(得分:-2)
查看此代码,这肯定会对您有所帮助。
<?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);
?>