If I just add the header in the mailable:
public function headers()
{
return new Headers(
text: [
'Return-Path' => config('mail.from.address'),
],
);
}
I get an error:
The "Return-Path" header must be an instance of "Symfony\Component\Mime\Header\PathHeader" (got "Symfony\Component\Mime\Header\UnstructuredHeader").
Only solution I found was with "using" in Envelope:
public function envelope()
{
return new Envelope(
using: [
function (Email $message) {
$message->getHeaders()->addHeader('Return-Path', config('mail.from.address'));
},
]
);
}
That works for me.
I also tried to add a name:
use Symfony\Component\Mime\Address as SymfonyAddress;
$message->getHeaders()->addHeader('Return-Path', new SymfonyAddress(config('mail.from.address'), config('mail.from.name')));
But that creates an invalid result:
Return-Path: <"Some Name" <[email protected]>>
I guess name is not supported here?
In your Mailable build() function you can do something like this:
use Symfony\Component\Mime\Email;
$this->withSymfonyMessage(function (Email $message) {
$message->getHeaders()->addPathHeader('Return-Path', "EMAIL_ADDRESS_HERE");
});
Works for me in Laravel 11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With