Rob
Rob

Reputation: 11388

Laravel Mailgun Driver Custom Tags

I'm trying to add a custom Mailgun tag to my email. I've seen lots of examples including in the Laravel documentation, but it's just not working for me:

<?php

namespace App\Mail;

use App\Models\User;

use Illuminate\Mail\Mailable;

class TestMail extends Mailable
{
    public function build()
    {
        echo 'build';

        $this->withSymfonyMessage(function ($message) {
            echo 'tag';
            $message->getHeaders()->addTextHeader('X-Mailgun-Tag', 'test');
        });

        return $this;
    }

    public function handle(User $recipient)
    {
        $body = 'test body';
        $subject = 'test subject';

        $this->html($body);
        $this->subject($subject);
        $this->from(config('mail.from.default.address'), config('mail.from.default.name'));
        $this->to($recipient->email, $recipient->first_name);

        return $this;
    }
}

I can see the "build" echo but not the "tag" echo. I can see the email in the Mailgun logs is going through but the "tags" array is empty. And can't find any tag at all in Mailgun. Is there a way to inspect the mail send from Laravel and verify the header is getting attached? Something else on the Mailgun side that needs to be enabled?

Upvotes: 2

Views: 124

Answers (0)

Related Questions