Earlier I outlined a problem I was trying to solve via the Bronto SOAP API. To give you a better idea what I’m going for, here’s a more extensive description …
When people purchase something from my client, at the bottom of the form, there is a checkbox they can check to elect to subscribe to my client’s email list. We want to do a double opt-in situation … so once they check out, they’ll then need to be sent a confirmation email, and then they confirm their subscription. The idea is that we want to be absolutely sure that the people on the receiving end of my client’s marketing emails really do want to receive them.
In my client’s Bronto account, we’ve set up a confirmation/welcome email, and previously we were importing the list of emails on a weekly basis. When you manually import contacts like this, Bronto gives you the option of sending a confirmation email. We wanted to automate this process such that each person was automatically sent a confirmation email within moments of checking out. The big issue was that many people were failing to confirm, probably because of the time difference between them actually buying and receiving the confirmation email.
The problem … in Bronto, you cannot use the API to simply send a pre-existing message (our welcome/confirmation message) to a single person … you have to send to a list.
So, my first idea was to automatically add each user to a “Confirmation Queue” mailing list. Every five minutes or so, I’d have an automated process run that scheduled a delivery of the welcome/confirmation message to everybody in the “Confirmation Queue” … and then the next time the script ran, those people would be removed from the queue, and it would schedule another delivery to the people still in the queue (if there were any).
I quickly ran into a problem with my new plan … Bronto won’t send a message to an unconfirmed contact (as far as I can tell). Of course, the contact has to be unconfirmed until they get the confirmation message, otherwise we run the risk of sending messages to people who haven’t completed the double opt-in process for some reason. And … there doesn’t appear to be any way to tell Bronto that I’m sending a confirmation message, and thus actually send to these people. So … it’s time for a new plan.
My new plan involves handling the confirmation email myself … I’ll store a list of people who have completed the first step of the confirmation process (the checkout opt-in), and immediately send them a confirmation email. The confirmation link in the email will trigger my app, which will then add them to the appropriate mailing list in Bronto as verified people, and remove them from the queue. People who haven’t confirmed within 7 days will be removed automatically. So … this appears to be a workable solution.
But … what if you do want to send an email from Bronto? Well, first we’re going to assume you’ve actually already created the message. What we’re going to do is add another method to my existing Bronto class from my previous post that will take care of this for us.
In order to send a message, we need the Bronto ID of at least one list (or segment), and the Bronto ID of the message we want to send. I already showed you how to dump a list of your existing lists in the last installment … and getting a list of messages is equally simple … you just make a call to readMessages(). Add the following to your Bronto class:
public function dumpMessages()
{
header('content-type: text/plain');
print_r($this->_conn->readMessages());
exit;
}
Then just find the ID of the message you want to send. Now to send the actual message, add the following method to the Bronto class:
public function sendMessage($listID, $messageID)
{
// Set the default date to UTC, which is the way Bronto understands time.
date_default_timezone_set('UTC');
// Set up the parameters for our mailing.
$mailing = array(
'start' => date('Y-m-d h:i:s'),
'messageId' => $messageID,
'recipients' => array(
array('type' => 'list', 'id' => $listID)
),
'fromEmail' => 'sender@example.com',
'fromName' => 'Bronto Test',
'replyEmail' => 'replyto@example.com'
);
// Now we're going to send the message.
$rs = $this->_conn->writeDeliveries(array(
'deliveries' => array($mailing),
'handler' => array('mode' => 'insert')
));
}
Now … let’s look at what’s happening with the writeDeliveries() method … you’re passing it two parameters, ‘deliveries’ and ‘handler.’ ‘Deliveries’ is an array, and it will contain one or more associative arrays (or hashes) describing the mailing or mailings that you are scheduling. All of the items I’ve put in my $mailing array are required. The ’start’ parameter describes when the mailing will be sent. It is important that you define your timezone as UTC as I’ve done, and also assure that the time on your server is accurate … otherwise your mailing may not be sent when you expect. As far as I can tell, if you specify any time in the past here, Bronto will schedule the mailing to go out as soon as possible.
The ‘recipients’ property can take an array of associative arrays, each of which describe a list. The ‘type’ is either going to be ‘list’ or ’segment’.
For the ‘handler’ option in writeDeliveries(), there is only one option, mode, and it can only be set to ‘insert’. Go figure. You’d think it would be optional in this case, but it isn’t … perhaps in the future there will be more options here, maybe so you can modify a mailing scheduled in the future.
Beyond that, it should be pretty self explanatory. Good luck!


Latest Comments
RSS