0

Hi still learning so please be nice :)

I have a PHP the following PHP code which sends a transactional email using Mailjet php class

    $body = [
    'Messages' => [
  [
    'From' => [
      'Email' => "$fromemail",
      'Name' => "$fromname"
    ],
    'To' => [
      [
        'Email' => "$toemail",
        'Name' => "$fullname"
      ]
    ],
    'TemplateID' => 1203229,
    'TemplateLanguage' => true,
    'Subject' => "Welcome to ABC",
     'Variables' => json_decode('{
"name": "Colin",
"referred": "referredby",
"volume": "1000",
"mobile": "number",
"email": "abc@gmail.com",
"firstline": "address",
"postcode": "SU99 1aa",
"landline": "number",
"services": "Service",
"delivery": "delivery",
"contact": "email",
"termsagree": "Yes"

I would like to use variables in the json decode however i get 500 errors I tried to change the json decode into an array however I still have the same problem

Can anyone see what I am doing wrong?

Array test

Variables' = array( "name" => "Colin", "referred" => "referredby", "volume" => "1000" "email" => "abc@gmail.com" "firstline" => "address" "postcode" => "SU99 1aa" "landline" => "number" "services" => "services" "delivery" => "delivery" "contact" => "email" "termsagree" => "Yes"

Updated code with array

  $body = [
    'Messages' => [
  [
    'From' => [
      'Email' => "$fromemail",
      'Name' => "$fromname"
    ],
    'To' => [
      [
        'Email' => "$toemail",
        'Name' => "$fullname"
      ]
    ],
    'TemplateID' => 1203229,
    'TemplateLanguage' => true,
    'Subject' => "Welcome to ABC",
    'Variables' => array(
"name" => "Colin",
"referred" => "RColin",
"volume" => "1000"
"email" => "abc@gmail.com"  
"firstline" => "address"
"postcode" => "POST CODE"
"landline" => "number"
"services" => "SMS"
"delivery" => "Direct"
"contact" => "Colin"
"termsagree" => "Yes"
mcgster
  • 15
  • 6
  • `'Variables' => array(),` – u_mulder Jun 10 '20 at 11:21
  • thank you u_mulder however still getting a 500 error :( syntax error, unexpected '"email"' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /var/www/html/test2.php on line 54 - looking line 54 ("email" => "abc@gmail.com" ) i have remove the "@" sign just in case and tried again same problem – mcgster Jun 10 '20 at 11:29
  • Sorted now :) - missing the "," at the end on everything on the array – mcgster Jun 10 '20 at 11:44

0 Answers0