Asked by Iqbal · · 2 answers
The following code is works perfect for me, and I can send multiple attachment with the email. So here is the code:
Here is my SendMail
mailable class:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class SendMail extends Mailable
{
use Queueable, SerializesModels;
public $body;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($request)
{
$this->body = $request->body;
$this->attachment = $request->file;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$mail = $this->subject('Mail from Real Programmer')->view('admin.emails.sendmail');
if ($this->attachment) {
foreach($this->attachment as $file)
$mail->attach($file->getRealPath(), [
'as' => $file->getClientOriginalName(),
'mime' => $file->getMimeType()
]);
}
}
}
Here is the controller where I received the post request. This post request has multiple files uploads, And I am sending the whole request to my sendmail.php
public function mailsend(Request $request)
{
$people = User::get();
foreach($people as $p){
Mail::to($p->email)
->send(new SendMail($request));
}
}
return redirect()->back();
}
Hope it helped to you.
0
0