Laravel 邮件::发送多个附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25917977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Mail::send with multiple attachment
提问by Yadhu Krishnan
How can i send a mail with multiple attachments in laravel?
如何在laravel中发送带有多个附件的邮件?
This is my laravel controller:
这是我的 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('[email protected]', $_POST['subj']);
$message->to($_POST['to'])->subject($_POST['subj']);
$message->attach($_POST['attach']);
}, true);
Help::send_mail($data_mail, array($_POST['to']), array('[email protected]'));
}
All attachments are available in array $path
.
所有附件都在 array 中可用$path
。
It's showing error basename() expects parameter 1 to be string, array given
.
它显示错误basename() expects parameter 1 to be string, array given
。
But when I use $_POST['attach'] = $path[0];
instead of $_POST['attach'] = $path;
, mail is received with only one attachment.
但是当我使用$_POST['attach'] = $path[0];
而不是 时$_POST['attach'] = $path;
,收到的邮件只有一个附件。
回答by Chintan Parekh
As far as my knowledge, you can just use a for loop for all the attachments. Some this like this:
据我所知,您可以对所有附件使用 for 循环。有些像这样:
$data_mail = Mail::send($tmp, array('msg'=>$msg), function($message) use ($path) {
$message->from('[email protected]', $_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);