php - 使用 laravel 发送多张图片
问题描述
我想通过电子邮件发送多张图片。我是 laravel 的新手,我不知道如何添加多个附件。但得到下面的方法。
发送电子邮件控制器:
foreach (json_decode($img_files) as $img_file) {
$imgName = $img_file->name;
$pathToFile[] = ['path' => public_path() . "\\uploads\\" . $imgName];
}
//send the email to the relevant customer email
Mail::to($customer_email)->send(new SendMail($customer_firstname, $pathToFile), function ($message) {
// $message->attach($pathToFile);
foreach ($pathToFile as $path) {
$pathToFile = $path->path;
$message->attach($pathToFile);
}
});
dd($pathToFile) 的输出
array:2 [
0 => array:1 [
"path" => "C:\xampp\htdocs\bit-project\public\uploads\photo_2019-11-08_23-11-50.jpg"
]
1 => array:1 [
"path" => "C:\xampp\htdocs\bit-project\public\uploads\photo_2019-11-08_23-11-55.jpg"
]
]
在电子邮件模板中,这是我添加图像的方式:
<img src="{{ $message->embed($pathToFile) }}" style="width:600px;height:335px">
如上所述,我有一个包含上传图像路径的数组。我如何遍历这个数组以将其传递给SendMail
. 感谢你的帮助!
(编辑):这是 SendMail 类的代码
public function __construct($customer_firstname, $pathToFile)
{
$this->customer_firstname = $customer_firstname;
$this->pathToFile = $pathToFile;
}
public function build()
{
return $this->subject('Thank you! - Advance Car Diagnostics (Pvt.)Ltd')
->view('admin.email_template')
->with('data', $this->customer_firstname);
}
我将构建方法编辑为:
public function build()
{
$email = $this->subject('Thank you! - Advance Car Diagnostics (Pvt.)Ltd')
->view('admin.email_template')
->with('data', $this->customer_firstname);
foreach($this->pathToFile as $filePath){
$email->attach($filePath);
}
return $email;
}
但它给出了这个错误:basename () expects parameter 1 to be string array
解决方案
推荐阅读
- ssis - 需要将 SSIS 变量传递给执行进程任务来为 Winscp 生成动态命令行参数
- jrules - 使用 Java 代码/API 从 ODM 决策中心检索可读格式的决策表
- node.js - axios 第一个请求成功 第二个请求失败
- intellij-idea - IntelliJ:突然,现有的导入不再起作用 - 找不到要前往的声明
- reactjs - 将堆栈导航与抽屉导航通信以登录
- java - STOMP sockJS 和 ActiveMQ over Jetty 服务器
- amazon-dynamodb - DynamoDB 多对多关系,或者,我应该使用 Dynamo 吗?
- laravel - 在 Laravel 中使用前缀时,索引“/”路由不起作用
- reactjs - 在数据加载之前不要渲染 - 反应
- c# - 无效参数:不支持的定位器策略:null - 使用 chrome 驱动程序 76.0.3809.126