Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mateoo88's avatar

replyTo

I have a contact form for users. My envelope looks like this:

public function envelope(): Envelope
    {
        return new Envelope(
            replyTo: new Address($this->details['email'], $this->details['name']),
            subject: 'Contact',
        );
    }

Unfortunately, when a user fills out the form fields for ex. name: John and email: [email protected] we receive the following error:

Email "John" does not comply with addr-spec of RFC 2822.

When I remove replyTo:, everything works, and the form is sent. I use Mailtrap to handle email in my application. Has anyone a similar problem? And do you know how to solve it?

0 likes
2 replies
jlrdw's avatar

Not knowing everything about your app, I suggest lookup RFC 2822.

Are you sure a valid formatted email is in $this->details['email']?

Do a:

dd($this->details['email']);

And or check the network request and response tabs.

Snapey's avatar
Snapey
Best Answer
Level 122

The envelope is not at all obvious. I tried to raise an issue but it was rejected.

Simple answer is that you need to provide an array

public function envelope(): Envelope
    {
        return new Envelope(
            replyTo: new Address([$this->details['email'] => $this->details['name']]),
            subject: 'Contact',
        );
    }

edit:

I may not have remembered it quite right. Here is the issue;

https://github.com/laravel/framework/issues/50430

try this instead

public function envelope(): Envelope
    {
        return new Envelope(
            replyTo: [new Address($this->details['email'], $this->details['name'])],
            subject: 'Contact',
        );
    }

1 like

Please or to participate in this conversation.