'Trouble to send multiple attachment mail in laravel
Here is my controller code.
$fileArray=$request->multiple_file;
$data['name']="custom size mail";
$message='ok message';
Mail::send('emails.cutom_size_admin', $data, function($message) use ($fileArray)
{
$message->from('[email protected]', 'Laravel');
$message->to('[email protected]')->cc('[email protected]');
for ($i=0; $i < count($fileArray); $i++) {
$message->attach($fileArray[$i]);
}
});
and my CustomSizeMailToAdmin.php mailable code is -
public function build()
{
$email= $this->from('[email protected]','Make Subject')->subject('Contact Mail')->view('emails.cutom_size_admin')->with('data', $this->data);
foreach($attachments as $filePath){
$email->attach($filePath);
}
return $email;
}
And my form html is-
<input type="file" multiple name="multiple_file[]" id="multiple_file">
Solution 1:[1]
I did it.
Now here is my controller code-
$fileArray=$request->multiple_file;
for ($i=0; $i < count($fileArray); $i++) {
$fileext = $fileArray[$i]->getClientOriginalExtension();
$data['filepath'][$i]['fileimg'] = now()->format('dmyHis') .mt_rand(1000000, 9999999). '.' . $fileext;
$destinationPath = 'public/assets/images/customsize/';
$data['filepath'][$i]['filemove'] = $fileArray[$i]->move($destinationPath,
$data['filepath'][$i]['fileimg']);
}
if(isset($toEmail) && $toEmail!=''){
Mail::to('[email protected]')->send(new CustomSizeMailToAdmin($data));
}
and my CustomSizeMailToAdmin.php mailable code is -
public function build()
{
$email= $this->from('[email protected]','Make Subject')->subject('Contact Mail')->view('emails.cutom_size_admin')->with('data', $this->data);
foreach($this->data['filepath'] as $filePath){
$email->attach('https://makemyfoam.com/'.$filePath['filemove']);
}
return $email;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |