Install the SendGrid category in the Laravel mail library

I am sending an email to Laravel via SendGrid using the configuration suggested in SendGrid Docs .

Just to give an example of what it looks like now:

Mail::send('emails.demo', $data, function($message)
{
    $message->to('jane@example.com', 'Jane Doe')->subject('This is a demo!');
});

The email itself works fine, but I would like to add the SendGrid category. I have done this in past projects other than Laravel using the method addCategory()in this repo .

My question is: is there an easy way to add the SendGrid category using the Laravel mail library, or does it make sense to just use the SendGrid PHP library?

+4
source share
3

, .

+2

, X-SMTPAPI, , Laravel , SwiftMailer. ,

0

, :

:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('mail')
        ->from('')
        ->subject('')
        ->withSwiftMessage(function($message) {
            $message->getHeaders()->addTextHeader(
                'X-SMTPAPI', json_encode(['category' => 'testing category'])
            );
        });
}
0

Source: https://habr.com/ru/post/1612809/


All Articles