1, // 'features' => SOAP_SINGLE_ELEMENT_ARRAYS) // ); $opts = array( 'ssl' => array('ciphers'=>'RC4-SHA') ); ini_set( "soap.wsdl_cache_enabled", "0" ); $client = new SoapClient( 'https://api.bronto.com/v4?wsdl', array ( "encoding"=>"ISO-8859-1", 'stream_context' => stream_context_create($opts), "trace"=>1, "exceptions"=>1, "features"=>SOAP_SINGLE_ELEMENT_ARRAYS, "connection_timeout"=>10 )); setlocale(LC_ALL, 'en_US'); function not_empty_string($s) { return $s !== ""; } // Calling toolkit paremeters $twscn = $_REQUEST['atcn']; //coupon $twsem = $_REQUEST['atem']; //email $twsfn = $_REQUEST['atfn']; //first name $twsln = $_REQUEST['atln']; //last name $twsot = $_REQUEST['atot']; //order total $twsbk = $_REQUEST['atbk']; //basket string $twsms = $_REQUEST['atms']; //bronto message try { // Add API token here $token = "4609034B-8B77-4C94-A4A3-A13785BBA47A"; print "logging in\n"; // The session will end if there is no transaction for 20 minutes. $sessionId = $client->login(array('apiToken' => $token))->return; $session_header = new SoapHeader("http://api.bronto.com/v4", 'sessionHeader', array('sessionId' => $sessionId)); $client->__setSoapHeaders(array($session_header)); // Get the id of the message you will use in the delivery. It would be more // efficient to hardcode the ID here, and you may choose to do that // based on your own usage scenario(s). $filter = array('name' => array('operator' => 'EqualTo', 'value' => $twsms) ); $message = $client->readMessages(array('pageNumber' => 1, 'includeContent' => false, 'filter' => $filter) )->return[0]; if (!$message) { print "There was an error retrieving the message ID.\n"; exit; } // Trigger an addOrUpdateContacts() call. If the contact is new, // set their status to 'transactional'. This will not update an // existing contact's status, but it will allow you to send // transactional emails to new contacts who have not opted-in to // receive promotional/marketing emails. $contact = array('email' => $twsem, 'status' => 'transactional' ); print "Adding contact with the following attributes" . $twsem . "\n" ; $contact_write_result = $client->addOrUpdateContacts(array($contact))->return; if ($write_result->errors) { print "There was a problem adding or updating the contact:\n"; print_r($contact_write_result->results); } elseif ($contact_write_result->results[0]->isNew == true) { print "The contact has been added with a status of 'transactional'. Contact Id: " . $contact_write_result->results[0]->id . "\n"; } else { print "The contact already exists. You can send transactional emails to them. Contact Id: " . $contact_write_result->results[0]->id . "\n"; } // Make delivery start timestamp $now = date('c'); $deliveryRecipientObject = array('type' => 'contact', 'id' => $contact_write_result->results[0]->id); // Create an array of delivery parameters including the content // which will be displayed by the loop tags added in the bronto // message. $delivery = array(); $delivery['start'] = $now; $delivery['messageId'] = $message->id; $delivery['fromName'] = 'The Workwear Store'; $delivery['fromEmail'] = 'orders@theworkwearstore.com'; $delivery['recipients'] = array($deliveryRecipientObject); $delivery['type'] = "transactional"; // Notice below that when you reference the name of the loop tag via the API, // be sure to leave of the "%%# _#%%" portion of the tag. You will build // an array using individual API message tags which are named // as follows: basename_number. For example, name => item_1, rather // than name => %%#item_#%%. The ^ character is the record delimiter and the , // character is the field delimiter $i = 1; var_dump($twsbk); $items = array_filter(explode('^',$twsbk), 'not_empty_string'); // var_dump($items); foreach($items as $item) { $item_part = explode(',',$item); $delivery['fields'][] = array('name' => 'productcode_'.$i, 'type' => 'html', 'content' => $item_part[0]); $delivery['fields'][] = array('name' => 'productname_'.$i, 'type' => 'html', 'content' => $item_part[1]); $delivery['fields'][] = array('name' => 'productqty_'.$i, 'type' => 'html', 'content' => $item_part[2]); $delivery['fields'][] = array('name' => 'productprice_'.$i, 'type' => 'html', 'content' => $item_part[3]); $i++; } $delivery['fields'][] = array('name' => 'coupon', 'type' => 'html', 'content' => $twscn); $delivery['fields'][] = array('name' => 'fname', 'type' => 'html', 'content' => $twsfn); $deliveries[] = $delivery; // var_dump($delivery); $parameters = array('deliveries' => $deliveries); $res = $client->addDeliveries($parameters)->return; if ($res->errors) { print "There was a problem scheduling your delivery:\n"; print $res->results[$res->errors[0]]->errorString . "\n"; } else { print "Delivery has been scheduled. Id: " . $res->results[0]->id . "\n"; } } catch (Exception $e) { print "uncaught exception\n"; print_r($e); } ?>