How can i send a mail with multiple attachments in laravel?
This is my laravel controller:
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'));
}
All attachments are available in array $path
.
It's showing error 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.
As far as my knowledge, you can just use a for loop for all the attachments. Some this like this:
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.