user2456410
user2456410

Reputation: 41

How to use variables in mailgun API?

How I can use variables in mailgun?

In the test email ([email protected]) I added the following variable

{"age": 20}

but it does not go as is used when creating the mail.

Here goes the code when the mail is sent.

$mailformat = "CODE HTML :D";
$result = $mgClient->sendMessage($domain, array(
    'from'    => 'Example <[email protected]>',
    'to'      => '[email protected]',
    'subject' => '%recipient_fname%, testing mail',
    'html'    => $mailformat
));

Upvotes: 3

Views: 5835

Answers (2)

You should add the user variables this way:

v:age=20

If you're using Python, in the data element you must add

data={
   'from' : 'Name <email@email>',
   'to'   : email_list,
    ...
   'v:age' : '20'
}

Upvotes: 5

Jim Wright
Jim Wright

Reputation: 6058

From the documentation:

v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.

Upvotes: 1

Related Questions