Problem with subscriberAddWithCustomFields in PHP

Hi All,

I'm trying to make subscriberAddWithCustomFields works with the PHP Sample and I'm having problems for the last 5 hours with it, so it's time to ask for a little help

I have a list with two custom fields, one is Multi-Options (select many) (called 'opcoes'), and the other is a Multi-Options (select one)(called 'mes'), and I can't figure out how I need to code this to make it insert the two fields heres my code:


$api_key = 'APIKEY';
$list_id = 'LISTID';

$cm = new CampaignMonitor($api_key, null, null, $list_id,'soap');

$userEmail = "EMAIL";
$userName = "NAME";
$informations = array('opcoes' => 'Taco el Pancho', 'Todos'), array('mes' => 'mar')

$result0 = $cm->subscriberAddWithCustomFields($userEmail, $userName, $informations);

$result1 = $cm->subscribersGetActive();

print_r($result0); //Array ( [code] => 0 [Message] => Success )

print_r($result1); // It's empty ( how I can Successfully add, and the user don't show up it's weird to me, I've tried without the $informations bit and the result is the same )[/code]
Any Clue ??

And please CM, could you add some simple examples about using the API Samples ?

Marcelo Wolfgang

Ken Ken, 8 years ago

Hi Marcelo,

You need to use this following line:

$informations = array('opcoes' => array('Taco el Pancho', 'Todos'), 'mes' => 'mar');

This should work now.

The file Subscriber.AddWithCustomFields.php from does have an example of how to format the custom field array.

Feel free to get back to us if you have any other problems or questions.
grillo, 8 years ago

Hi Ken,

Thanks for the response, After a couple of more try and error I came up with:

$informations = array("opcoes" =>array ( "taco el pancho","soviet"), "mes" =>array ("mar"));

which is the same thing, actually it was more of a lack of knowledge of php from my part than anything else.


Paul Davis, 8 years ago


I'm having similar problems getting this to work. I've tried the suggestions above but no joy :(

Script is as follows:

    $api_key = 'my_api_key';
    $client_id = null;
    $campaign_id = null;
    $list_id = 'my_list_id';
    $cm = new CampaignMonitor( $api_key, $client_id, $campaign_id, $list_id, 'soap');
    $result = $cm->subscriberAddWithCustomFields($Email, $Name, array('Title' => $Title));
    if($result['Code'] == 0)
        echo 'Success';
        echo 'Error : ' . $result['Message'];

I have the permissions of both this and the CMBase.php set to 755.

The variables $Email, $Name, and $Title are passed from a form which uses a POST action pointing at this php script.

Can anyone tell me what I'm doing wrong?

Much appreciated!!

grillo, 8 years ago

I couldn't figure out what was wrong, but maybe:

array('Title' => $Title)

should be

array('Title' => '$Title')


200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free