php - SendGrid unique arguments with individual emails -


i trying set list of unique arguments per each email, official reference of smtp api describes feature quite briefly, here.

and api docs of sendgrid php library using, didn't much:

 /**     * setuniquearguments    * set list of unique arguments, used tracking purposes    * @param array $key_value_pairs - list of unique arguments    */   public function setuniquearguments(array $key_value_pairs)   {     $this->header_list['unique_args'] = $key_value_pairs;     return $this;   }    /**    * adduniqueargument    * set key/value pair of unique arguments, used tracking purposes    * @param string $key   - key    * @param string $value - value    */   public function adduniqueargument($key, $value)   {     $this->header_list['unique_args'][$key] = $value;     return $this;   } 

so in fact, based implementation on obvious logical conclusion, , decided create multi-dimensional json unique-arguments part of header, 1 one correspondence substitution values array, , recipients array, unfortunately, didn't work, , resulted in invalid xsmtp api header error being bounced email.

if have used feature before, , can instruct me briefly on how use correctly (perhaps calling adduniqueargument after each addto?), can great me.

i see you're mentioning unique arguments first you're mentioning substitutions unrelated matter. unique arguments apply api call whole, example may contain batch id in system can more match email events data. substitutions, however, string replacement in emails personalize each email recipient , apply each recipient of email instead of api call.

sendgrid unique arguments

you don't have mess json request headers if you're using api library, use library other php object. example, if have set 3 variables, var1, var2, var3 it's either this:

$sendgrid -> setuniquearguments(array(     'var1' => 'value1',     'var2' => 'value2',     'var3' => 'value3' )); 

or this:

$sendgrid -> adduniqueargument('var1', 'value1'); $sendgrid -> adduniqueargument('var2', 'value2'); $sendgrid -> adduniqueargument('var3', 'value3'); 

the difference being first option setuniquearguments replaces other variables you've added before second one, adduniqueargument, adds variable existing ones.

sendgrid substitutions

let's you're using api library , have 2 recipients, bob@example.com , alice@example com, , need mention name in email. in case use placeholder string in body of email, wouldn't occur normally. in our case, let's assume be:

hello <<name>> 

where <<name>> placeholder recipients name. in case can construct api call such (i'm leaving out parts related email content, etc.):

$sendgrid -> addto('bob@example.com'); $sendgrid -> addto('alice@example.com'); $sendgrid -> addsubstitution('<<name>>', array('bob', 'alice')); 

the values in addsubstituion call must in same order recipient list.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -