This is a quick how to, for people interested in adding subscribers to their Campaign Monitor lists. What you’ll need:
- PHP 5 with SOAP built in.
- A Valid Campaign Monitor Account
- A Campaign Monitor list
What’s assumed:
- You have a form already that’s collecting name and email address
- You know how to do basic input filtering
## ALL VALUES BELOW WERE GENERATED BY A RANDOM STRING GENERATOR CHANGE VALUES BELOW ##
// Campaign Monitor API Key
define('CM_APIKEY','wuc4vab7fik9v');// Campaign Monitor List ID
define('CM_ANALYZEROPTIN_LIST_ID','lub2iv6keg9fost2e');// Which client you're doing this for.
define('CM_CLIENT_ID','kov1hal9at7nau2w');## ALL VALUES ABOVE WERE GENERATED BY A RANDOM STRING GENERATOR CHANGE VALUES ABOVE ##
$client = new SoapClient("http://api.createsend.com/api/api.asmx?wsdl");
$params->ApiKey = CM_APIKEY;
$params->ListID = CM_ANALYZEROPTIN_LIST_ID;
#$params->clientID = CM_CLIENT_ID;$params->Email = "someaddress@example.com";
$params->Name = "Example Name";$result = $client->AddSubscriber($params);
Stay tuned for the next part in this series, which explains how to handle the $result and handle any errors.

{ 5 comments… read them below or add one }
a number of points about this example:
1) SoapClient throws exceptions, so try/catch them.
2) AddSubscriber will add the same same email twice. It’s better to use AddAndResubscribe in my view to catch those who forget they’ve already subscribed.
[Reply]
BitChain,
You’re correct. I wanted to share the first step on how to do the connection and add in an ideal error free world first.
As for the AddSubscriber adding dupes, in my tests that wasn’t the case, I kept adding myself with the same email address in my tests, and only showed me added once. It did return a Success though. It’s either a bug on their end, or a “feature”
.
[Reply]
Hi, I keep getting an “Invalid ListId” error (code 101). I checked and rechecked to make sure the api key/list id was correct and it seems to be, however I can’t get this to work. Any advice? Also, would love to see how you handle the result. I can’t seem to access that object properly either. Seems to be an stdClass Object called “Subscriber.AddResult”.
I’m trying to do this:
$params->…etc, etc..
etc…
$res = $client->AddSubscriber($params);
echo $res->Code;
Thanks for the help,
Chris
[Reply]
Nevermind, I figured it out. I mistyped:
Changed From:
$params->ListId = ‘key’;
To:
$params->ListID = ‘key’;
[Reply]
Chris,
. I was out watching a movie
. Stay tuned for a more “robust” system in the next few weeks.
You beat me to it
[Reply]