Reputation: 102
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('[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
.
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.
Upvotes: 2
Views: 12455
Reputation: 1101
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('[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);
Upvotes: 13