framework: Mail with attachment CSV = bad content-type
- Laravel Version: 5.8.31
- PHP Version: 7.2.21
- Database Driver & Version: PostgreSQL
Description:
Hello,
I send specific email : plain text, with body totally empty and CSV file on attachment
public function build()
{
return $this->from(env('MAIL_SENDER'))
->bcc(str_replace('@', '+send@', env('MAIL_SENDER')))
->subject($this->cmd_acces->filename)
->text('emails.admin.ftth.cmd_acces.cmd_acces_mailer') // empty blade file
->attach($this->cmd_acces->csvfile, [
'as' => $this->cmd_acces->filename,
'mime' => 'text/csv',
]);
}
No problem with Laravel 5.5 but i’ve just upgraded to Laravel 5.8 and there’s a little bug :
The content-type should by “multipart/mixed” but it is now “plain/text”
Laravel 5.5 => OK
Laravel 5.8 => NOK => bad content-type and base64 on body message
I’ve change Illuminate/Mail/Mailer.php (https://github.com/laravel/framework/blob/6.x/src/Illuminate/Mail/Mailer.php#L332) and that’s work fine
Actual
$message->$method($this->renderView($plain, $data), 'text/plain');
My change : just deleted “text/plain” parameter
$message->$method($this->renderView($plain, $data));
I suppose a bug ?
Steps To Reproduce:
send email : plain text, with body totally empty and CSV file on attachment
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (9 by maintainers)
Commits related to this issue
- Move up message сustomization callbacks — committed to laravel/framework by Alexander-- 6 years ago
@driesvints I found the difference between 5.8 and 5.5
https://github.com/laravel/framework/blob/5.8/src/Illuminate/Mail/Mailer.php#L242
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Mail/Mailer.php#L220
On 5.5, call_user_func is after addContent
On 5.8 call_user_func is before addContent
On 5.8, if I move call_user_func like 5.5, that’s work fine…
I am the guy, who made 0cd889942c7d and ultimately broke everyone’s email in Laravel 5.6
In retrospect the change in #22995 was a bad idea. But I had my reasons!
Anyway, content type like
text/plain; boundary...
is an obvious nonsense, which makes me think that this is a bug in SwiftMailer.Internally SwiftMailer represents both primary message and all it’s parts as subclasses of
Swift_Mime_SimpleMimeEntity
and decides on hierarchy (and mime-types of parts) via some weird logic. So perhaps invokingSwiftMessage#attach()
beforeSwiftMessage#setBody()
causes an attachment to be miscategorised as primary part, which subsequently has it’s mime type set to text/plain? Just a wild guess.