gpt4 book ai didi

Laravel 邮件 Blade 传递变量

转载 作者:行者123 更新时间:2023-12-02 19:44:26 25 4
gpt4 key购买 nike

我需要将一些变量传递到我的发送电子邮件。

这是我的代码:

  $data = [
'first' => $request->first,
'last' => $request->last,
'business_org' => $request->business_org,
'instagram' => $request->instagram,
'email' => $request->email,
'phone' => $request->phone,
'unique' => $request->unique,
'purchased' => $request->products_purchased,
'city' => $request->city,
'state' => $request->state,
'filename' => $fileName
];

// send email with details
Mail::send('emails.justshoot', $data, function($message) {
$message->from('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f0a0c3f0c10121a0b17161118511c1012" rel="noreferrer noopener nofollow">[email protected]</a>', 'Just Shoot Upload');

$message->to('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="610c18040c00080d21060c00080d4f020e0c" rel="noreferrer noopener nofollow">[email protected]</a>')->cc('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d405448404c44416d4a404c4441034e4240" rel="noreferrer noopener nofollow">[email protected]</a>');
});

然后我尝试访问该变量,以便可以在电子邮件中显示它。emails.justshoot.blade.php

{{$data}} 给出错误。我做错了什么?

最佳答案

您对所做的事情完全没问题,但第二个参数是传递给 View 的数据,与调用 View 的 with([]) 方法一样,数组Passed 将为每个条目生成一个对象,因此您正在生成 $first, $last, $business_org 并且 $data 只是数组,因此它不会作为元素传递到 View :如果你想要这个,你应该将 [$data] 传递给邮件发送:

$data = [
'first' => $request->first,
'last' => $request->last,
'business_org' => $request->business_org,
'instagram' => $request->instagram,
'email' => $request->email,
'phone' => $request->phone,
'unique' => $request->unique,
'purchased' => $request->products_purchased,
'city' => $request->city,
'state' => $request->state,
'filename' => $fileName
];

// send email with details
Mail::send('emails.justshoot', [$data], function($message) {
$message->from('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7b2b487b4a8aaa2b3afaea9a0e9a4a8aa" rel="noreferrer noopener nofollow">[email protected]</a>', 'Just Shoot Upload');

$message->to('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cda0b4a8a0aca4a18daaa0aca4a1e3aea2a0" rel="noreferrer noopener nofollow">[email protected]</a>')->cc('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d9cdd1d9d5ddd8f4d3d9d5ddd89ad7dbd9" rel="noreferrer noopener nofollow">[email protected]</a>');
});

然后在 View 中您可以执行{{$data}}

提示:您应该使用 php artisan 创建邮件,然后您就可以以更优雅的方式做任何您想做的事情

关于Laravel 邮件 Blade 传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59587146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com