如何在laravel中发送带有多个附件的邮件?
这是我的laravel控制器:
public function send_approve_mail($to, $subj, $tmp, $path) {
$_POST['subj'] = $subj;
$_POST['to'] = $to;
foreach ($path as $key => $value) {
$path[$key] = '../public/assets/fax/extra/' . $value;
}
$_POST['attach'] = $path;
$msg = "test message here";
$data_mail = Mail::send($tmp, array('msg' => $msg), function($message) {
$message->from('xxx@xxx.com', $_POST['subj']);
$message->to($_POST['to'])->subject($_POST['subj']);
$message->attach($_POST['attach']);
}, true);
Help::send_mail($data_mail, array($_POST['to']), array('xxx@xxx.com'));
}
Run Code Online (Sandbox Code Playgroud)
所有附件都以阵列形式提供$path.
它显示错误basename() expects parameter 1 to be string, array given.
但是当我使用$_POST['attach'] = $path[0];而不是$_POST['attach'] = $path;,只收到一个附件的邮件.
Chi*_*ekh 12
据我所知,你可以为所有附件使用for循环.有些像这样:
$data_mail = Mail::send($tmp, array('msg'=>$msg), function($message) use ($path) {
$message->from('xxx@example.com', $_POST['subj']);
$message->to($_POST['to'])->subject($_POST['subj']);
$size = sizeOf($path); //get the count of number of attachments
for ($i=0; $i < $size; $i++) {
$message->attach($path[$i]);
}
},true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9887 次 |
| 最近记录: |