I'm redoing a project that has SendGrid integrated for mailing.
Well, I'm using Laravel and Mailable classes, and I have created a function to set the SendGrid category:
public function setSendgridCategory($category){
$encodedCategory = json_encode(['category' => $category]);
$this->withSwiftMessage(function (\Swift_Message $message) use ($encodedCategory){
$message->getHeaders()->addTextHeader('X-SMTPAPI', $encodedCategory);
});
}
I have a listener which logs my headers, and they look like:
Date: Wed, 18 Jan 2017 13:47:32 +0100
Subject: XXXXXXXXX.
From: xXXXXXx <[email protected]>
To: XXXXxxx <[email protected]>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-SMTPAPI: {"category":"Otros"}
Also tried with an array
X-SMTPAPI: {"category":["Otros"]}
The name of the category is exactly the same as the one that is already being tracked on SendGrid, but when I look on the SendGrid activity log, the email is sent, but no category is set.
Any ideas?
Category needs to be an array. Try: {"category":["Otros"]}
Well, after testing everything that came to my mind, and messing with the encodings as @bwest suggested, changing the driver on my .env file solved it.
I don't know where did I get it from, but I had my driver set as
MAIL_DRIVER=sendgrid
and it was sending mails correctly, so I didn't pay attention to it, I changed it to
MAIL_DRIVER=smtp
and now my categories are set correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With