I want to attach file on email from user input files on application form, but I dont know hot to do it properly. I tried this code but the attached files are invalid files(pictures, pdf etc..) when opening after downloading the attached files. Here is my code
public function __construct(Request $request, Position $position)
{
$this->request = $request;
$this->position = $position;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$email = $this->from('xxxx@xxxxx.com', $this->request->first_name . ' ' . $this->request->last_name)
->replyTo($this->request->email, $this->request->first_name . ' ' . $this->request->last_name)
->subject('Application for ' . $this->position->name)
->view('emails.application');
$counter = 1;
foreach($this->request->resume as $resume) {
if ($resume->isValid()) {
$path = $resume->path();
$extension = $resume->extension();
$email->attachData($path, 'file' . $counter. '.' . $extension);
}
$counter++;
}
return $email;
}