There is a similar question here: "Unable to open file for reading" (Swift_IoException) in Laravel Mailable
However the accepted answer doesn't solve my problem. I also saw the documentation for attachments
I am trying to attach file while sending mail and here is my code.
public function build()
{
$folder = public_path('/email');
//Get a list of all of the file names in the folder.
$files = glob($folder . '/*');
//dd($files[]);
if (!empty($files)) {
return $this->subject($this->subject)->markdown('mail.newsletter')->with('data', $this->data)->attach(public_path('/email') . $files[0]);
}else{
return $this->subject($this->subject)->markdown('mail.newsletter')->with('data', $this->data);
}
}
I get this error while program enters into if condition.
Swift_IoException Unable to open file for reading [/home/riwaj/Desktop/Project/Library/public/email/home/riwaj/Desktop/Project/Library/public/email/attachment.jpg]