Newbie Help: Adding a contact, email only

Regular Participant

Newbie Help: Adding a contact, email only

I am using PHP and the class provided and I can get an array of all my lists.  However I get an error when trying to add a new user.  Here is my code:


//create the CC objects
$ccListOBJ = new CC_List(); 
$ccContactOBJ = new CC_Contact();	
$postFields = array();
$postFields["email_address"] = $emailaddress; //
$postFields["lists"] = $theid; //[username]/lists/2
$contactXML = $ccContactOBJ->createContactXML(null,$postFields);	
if (!$ccContactOBJ->addSubscriber($contactXML)) 
	echo "<br>NOT ADDED<br>";
	echo "<br>ADDED<br>";

 and the error I get back is: Invalid argument supplied for foreach() [filepath] on line 491.


Any thoughts?


Hey Jeffrey,


I am unsure of which wrapper you are using but I suggest trying out our wrapper that is on GitHub.  Based on what your trying to do this would be the following code to do what you want with the other wrapper.


	include ('wrapper/ConstantContact.php');
	$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");

	//Get potential contact lists
	$lists = $ConstantContact->getLists();
	$contactObj = new Contact();
	$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
	$contactObj->emailAddress = '';
	// Create the contact
	$Contact = $ConstantContact->addContact($contactObj);


 Just replace the information at the top with your information in the connection string.  You can find the documentation and the wrapper itself here.


If you don't want to use that wrapper please let me know which one you are using so I can trouble shoot this further for you.



Ryan Davis
Quality Engineer
Regular Participant

I am using the PHP sample files on this page which includes a constant contact class.  I may try your method as it looks simpler but just for completeness and for anyone else searching can advise based on the PHP files based on this page (using the simple contact form):


I am glad that helped, please let me know if you need anymore help.



Ryan Davis
Quality Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page