Archive for the ‘Bronto’ Category

Bronto API PHP Class to Send a Contact a particular Message (Zend Helper)

Thursday, August 25th, 2011

< ? php
Zend_Controller_Action_Helper_BrontoSendMessage extends Zend_Controller_Action_Helper_Abstract {

public $message;
public $client;
public $viewData;
public $list;
public $now = “date(‘c’)”;
public $recipientObject;
public $email;
public $contact;
public $contactId;

private $fromName = ‘WHATEVERYOUWOULDLIKE’;
private $fromEmail = ‘YOU@YOURMAIL.COM’;

public function login(){
ini_set(“soap.wsdl_cache_enabled”, “0”);

$wsdl = “”;
$url = “”;

$this-> client = new SoapClient($wsdl, array(‘trace’ => 1, ‘encoding’ => ‘UTF-8’));
$this-> client->__setLocation($url);

// Login
$sessionId = $this-> client->login(array(“apiToken” => $token))->return;
if (!$sessionId) {
return “Login failed”;
$this-> client->__setSoapHeaders(array(new SoapHeader(“”,
array(‘sessionId’ => $sessionId))));

$this-> viewData[‘login’] = “logged in”;

public function setContact($email){
$this-> email = $email;

$filter = array(’email’ => array(array(‘operator’ => ‘EqualTo’,’value’ => $this-> email)));

$this-> contact = $this-> client->readContacts(array(‘pageNumber’ => 1,
‘includeLists’ => true,
‘filter’ => $filter,
//return ‘Email not subscribed’;
$this-> contactId = $this->contact->return->id;
//return $this->contactId;

$this-> recipientObject = array(‘type’ => ‘contact’, ‘id’ => $this->contactId);

public function setDelivery($messageid){
$delivery = array(‘start’ => date(‘c’),
‘messageId’ => $messageid,
‘fromName’ => $this-> fromName,
‘fromEmail’ => $this-> fromEmail,
‘recipients’ => array($this-> recipientObject),

? >

called from another Zend Controller as a helper in this fashion:

$this-> _helper-> BrontoSendMessage->login();
$this-> _helper-> BrontoSendMessage->setContact($this-> email);
$this-> _helper-> BrontoSendMessage->setDelivery($this-> messageid);

Bronto Direct Import API import .csv file (upload) via HTML form post or via PHP CURL with code examples

Tuesday, August 23rd, 2011

We are building a Cassandra based system (of record) to capture emails so that we can handle 100k users converging on an online event as quickly as possible.  Rather than relying on our third party email marketing vendor, Bronto, to handle the volume we could possibly experience, and risk possibly failing (as others doing the same thing recently have done…cough cough….Oprah and Eckhart Tolle), we’ll build our own system that can be tested correctly, and thus handle the volume, and then we’ll dump said new emails in reasonably sized files out to Bronto, who will then send out confirmation emails for us…

This post covers the script that will take file exports from Cassandra (sorry, no Cassandra in this one…), and Post them to Bronto.  Below is an example that uses a standard HTML form Post, for understanding and comprehensiveness, and an example that uses CURL (which easily allows this process to happen as part of an ordinary CRON job).

First we have to set up, and get some connection values, from Bronto:

  • Log into Bronto
  • From the top menu select Home->Settings
  • select Data Exchange
  • scroll to the bottom to Direct Import and grab the following connection values:
    • URL:
    • site_id: YOUR_SITE_ID
    • user_id: YOUR_USER_ID
    • key: YOUR_KEY
Further reference, Bronto support docs are here:

Next let’s look at what this Post might look like as your common HTML form:

<form method=”post” action=”” enctype=”multipart/form-data”>
<input type=”text” name=”source” value=”Test Contacts” />
<input type=”text” name=”format” value=”csv” />
<input type=”file” name=”filename” value=”C:\xampp\htdocs\YOUSITEFOLDERPATH\batch.csv” />
<input type=”text” name=”site_id” value=”YOUR_SITE_ID” />
<input type=”text” name=”user_id” value=”YOUR_USER_ID” />
<input type=”text” name=”key” value=”YOUR_KEY” />
<input type=”submit” name=”submit” value=”submit” />

Next let’s look at what this Post might look like in a PHP script using CURL:

<? php
$fields = array(
source‘=>”Test contacts“,

/* The key here is the ‘@’ above, which tells CURLOPT_POSTFIELDS to UPLOAD that file, parenthesis critical! */

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘‘);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);

? >

Last but not least, make (or in our case receive from Cassandra export dump) the .csv file to be Posted.
First column, Email, 2nd through n filled with email addresses, save it as .csv comma delineated.
Yes, it’s actually that simple.
I hope this helps somebody.