Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using section header in Sendgrid

Tags:

php

sendgrid

I am trying to send emails through sendgrid in Zend application. I copy the php code from the sendgrid documentation (smtapi class and swift).

I create a template with places that should be substituted with %variable%. Now I create headers for sendgrid as defined here: http://docs.sendgrid.com/documentation/api/smtp-api/developers-guide/

In result I get something looking like this:

{
"to": ["[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"], 
"sub": {"%firstname%": ["Benny", "Chaim", "Ephraim", "Yehuda", "will"]}, 
"section": {"%postername%": "John Doe", "%postermail%": "[email protected]", "%categoryname%": "General", "%threadname%": "Completely new thread", "%post%": "This thread is to inform you about something very important", "%threadurl%": "http:\/\/hb.local\/forums\/general\/thread\/143", "%replyto%": "http:\/\/hb.local\/forums\/general\/thread\/143", "%unsubscribeurl%": "http:\/\/hb.local\/forums\/settings\/", "%subscribeurl%": "http:\/\/hb.local\/forums\/subscribe-thread\/id\/143\/token\/1b20eb7799829e22ba2d48ca0867d3ce"}
}

Now while all data defined in "sub" changes I cannot make section work. In the final email I still got %postername%. When I move this data to sub and repeat them for each email everything is working fine.

Has anyone a clue what I am doing wrong?

Docs for section are here: http://docs.sendgrid.com/documentation/api/smtp-api/developers-guide/section-tags/

like image 805
Zefiryn Avatar asked Nov 05 '22 09:11

Zefiryn


2 Answers

Just FYI, SendGrid recently published a new PHP library. You can find it at http://github.com/sendgrid/sendgrid-php

(full disclosure: I currently work at SendGrid and my team developed the new library)

like image 68
iandouglas Avatar answered Nov 10 '22 01:11

iandouglas


I found the solution. section is used after substitution and perform on what sub does. So if I wanted to use %postname% in all emails first I must make sure that sub will place %postname% somewhere in the content.

like image 28
Zefiryn Avatar answered Nov 09 '22 23:11

Zefiryn