0
使用Mail::queue
/Mail::send
發送郵件時,您必須單獨傳遞郵件模板和主題。是否可以在刀片模板內定義郵件主題?
有沒有辦法管理郵件模板中的主題(對多語言更好)。
I.e.作爲模板
mail.blade.php
This is the subject
Hello User,
foobar
使用Mail::queue
/Mail::send
發送郵件時,您必須單獨傳遞郵件模板和主題。是否可以在刀片模板內定義郵件主題?
有沒有辦法管理郵件模板中的主題(對多語言更好)。
I.e.作爲模板
mail.blade.php
This is the subject
Hello User,
foobar
第一線這並不難:
Mail::queue($template, $data, function (Message $message) use ($toUser, $sendingName, $sendingAddress) {
// take subject from first line of the template
$body = $message->getSwiftMessage()->getBody();
$bodyLines = explode("\n", $body);
if (count($bodyLines) == 0) {
Log::warning('Empty mail');
return;
}
$subject = $bodyLines[0];
unset($bodyLines[0]);
// send
$message->getSwiftMessage()->setBody(implode("\n", $bodyLines));
....
您正在使用什麼版本laravel的? – tomirons
你爲什麼要管理模板本身的主題行?如果你這樣做是爲了支持多語言,那就是resources/lang文件夾的用途。 –