Dec 13, 2024
0
Level 1
Umlauts in an email are displayed as question marks as soon as the email has attachments
Here you can see my mail class. In principle it works, but as soon as I have file attachments, the umlauts in the subject and content are displayed as question marks, which indicates a problem with UTF-8 encoding. But I don't understand why this only happens when you add attachments. Also, I don't know how to solve this either. The broken umlauts appear in Thunderbird, Apple Mail displays everything correctly.
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class MeasurmentMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(
public $mail_data
){}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
if($this->mail_data['bestaetigung_an_user']) {
return new Envelope(
subject: 'Aufmaßeingang Bestätigung',
);
}
return new Envelope(
subject: 'Neuer Aufmaßeingang',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'mails.newMeasurement',
with: [
'auftragsID' => $this->mail_data['measurement']->auftragsID,
'createdBy' => $this->mail_data['user'],
'attachments' => count($this->mail_data['attachments'])
]
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
$emailAttachments = [];
foreach ($this->mail_data['attachments'] as $attachment) {
$emailAttachments[] = Attachment::fromStorage($attachment)
->as(basename($attachment));
}
return $emailAttachments;
}
}
Does anybody know what i am doing wrong?
Please or to participate in this conversation.