这与问题没有直接关系,但对于那些在保留自定义 HTML 版本的同时搜索设置电子邮件的纯文本版本的问题,您可以使用此示例:
Mail::raw([], function($message) {
$message->from('contact@company.com', 'Company name');
$message->to('johndoe@gmail.com');
$message->subject('5% off all our website');
$message->setBody( '<html><h1>5% off its awesome</h1><p>Go get it now !</p></html>', 'text/html' );
$message->addPart("5% off its awesome\n\nGo get it now!", 'text/plain');
});
如果你问“为什么不将第一个参数设置为纯文本?”,我做了一个测试,它只需要 html 部分,忽略原始部分。
如果您需要使用附加变量,匿名函数将需要您使用use() 语句,如下所示:
Mail::raw([], function($message) use($html, $plain, $to, $subject, $formEmail, $formName){
$message->from($fromEmail, $fromName);
$message->to($to);
$message->subject($subject);
$message->setBody($html, 'text/html' ); // dont miss the '<html></html>' or your spam score will increase !
$message->addPart($plain, 'text/plain');
});
希望对大家有所帮助。