在我的数据库中,我保存了包含刀片标记的文本,如:
Hello {!! $name !!} how are you today.我将此文本传递给变量$text中的电子邮件模板。在电子邮件中,我使用{!!$text!}获取邮件中的文本。然而,当电子邮件发送时,它会显示{!符号而不是变量(也是传递的)。如何将刀片标记保存在数据库中,并将其传递给需要替换{!的代码!有什么!!}有正确的变量?
我的邮件功能.
$email = $order->email;
$name = $order->billingname;
 //The text From the database.
$emailText = Email::findOrFail(5);
$mailtext = $emailText->text;
Mail::send('emails.tracktrace', ['text'=>$mailtext'email' => $email, 'name' => $name],
function ($m) use ($code, $email, $name) {
    $m->from('info@domain.com', 'domain');
    $m->to($email, $name)->subject('Track your package!');
});更新
我找到了一个解决办法:
$mailtext = str_replace('[name]', $name, $mailtext);这样的话,用户可以使用名称,我仍然想知道如何使用它只与刀片。
发布于 2015-12-14 13:43:24
我使用了以下电子邮件,所有要替换的动态变量都类似于电子邮件模板中的“{{ $name }”。
我创建了一个数据数组,并直接与邮件库一起使用它。这样,您就可以在邮件模板中替换多个动态变量。
您需要将文本保存在电子邮件模板中,并从数据库中使用动态阀。
如果电子邮件的文本是动态的,并且来自数据库,则可以使用文本代替函数中的电子邮件模板,并传递$data变量数组,一次性替换它们。
$data = array('name' => $customer->Name, 'InvoiceID' => $dueinvoice["InvoiceNumber"],'AmountDue' => $dueinvoice["AmountDue"],'DueDate' => $duedate ,'CurrencyCode' => $dueinvoice["CurrencyCode"]); 
\Mail::queue('emails.DueDateNotification',$data, function($message) use($customer)
{
    $message->subject('DueDate Notification');
    $message->to($customer->EmailAddress);
}); 另一件事是尝试使用“queue”函数来处理邮件,因为它减少了负载,并将电子邮件添加到laravel电子邮件队列中并逐个发送。
希望这对你有帮助
https://stackoverflow.com/questions/34236569
复制相似问题