Summer Sale! All accounts are 50% off this week.

bradycharron's avatar

Testing email headers

I am including custom headers with an email that I am sending using the following code:

$this->withSwiftMessage(function ($message) use ($site) {
    $message->getHeaders()
        ->addTextHeader("key", value);
});

I would like to test that these headers are being set, but I don't see a way to test the message with the Mail::fake(). I have found older discussions that reference the following, but it results in an error:

$messages = app()->make('swift.transport')->driver()->messages();

Target class [swift.transport] does not exist.

I have also found some additional resources that point to packages like Mail Intercept. I feel like I am missing something though if I have to implement a package to get the headers in my test. Is there a way to retrieve headers from a mailable in a test?

0 likes
0 replies

Please or to participate in this conversation.