Laravel mail & attachData()
Hi,
I'm working on adding attachments to some mail I'm sending and I was wondering how you specify the file name if you don't know the file extension.
For example if I want to allow users to send excel files and pdfs, how would I create the file name based on it's extension? if that makes sense?
public function build()
{
return $this->view('emails.orders.shipped')
->attachData(
$this->pdf,
'name.pdf' // could be one of many file types
);
}
The attachDataarguements accepts the raw data for the attachment, the filename and an array of options, such as mine type.
https://laravel.com/docs/5.7/mail#attachments
Therefore if you want to be able change the attachment type you just need to pass in the correct values
->attachData(
$this->excel,
'name.xls'
);
It's up to you how you generate the raw data and filename as laravel won't do this for you.
Okay thank you for the advice
Please or to participate in this conversation.