Vikram Anand Bhushan
Vikram Anand Bhushan

Reputation: 4896

How to attach multiple files in mail in Laravel 4

Previously I was attaching a single pdf file like this to the mail function .

Mail::send('emails.questionnairefilled', $data1, function($message) use($htmltosend, $emails){
  $message->to($emails) 
    ->from('[email protected]')
    ->subject(Auth::user()->name.', '.Auth::user()->event.'- Questionnaire completed')
    ->attachData(
      $htmltosend,
      Auth::user()->name.'_questionnaire.pdf',
      array('mime'=>'application/pdf', 'Content-Disposition'=>'attachment')
    );
});

So if I have to attach more files then do I have to use the attachData() function multiple times or there is some other way .

Thanks

Upvotes: 1

Views: 1575

Answers (2)

Hamid Naghipour
Hamid Naghipour

Reputation: 3635

$path =[];
$path[] = '../path/your/number/one/file';
$path[] = '../path/your/number/two/file';
$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: 1

Ashish Ranade
Ashish Ranade

Reputation: 605

You can use another email package like Mailgun which helps you to send multiple attachment through his "attach" function

Upvotes: 1

Related Questions