May 23, 2022
0
Level 1
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?
Please or to participate in this conversation.