cancel
Showing results for 
Search instead for 
Did you mean: 

How can i create email campaign and email list and add contacts to that list using PHP wrapper

Occasional Contributor

How can i create email campaign and email list and add contacts to that list using PHP wrapper

Hi,

 

I am unable to get the parameters to add campaign, add list and add contact, i am using PHP Wrapper class. Could you please guide me how to these.

 

there is a function to create campaign but where all the email contect be set and how will it create in constant and how and what should i send to this function

 

public function addCampaign(Campaign $Campaign, VerifiedAddress $fromEmail, VerifiedAddress $replyEmail = null){
$replyEmail = ($replyEmail) ? $replyEmail : $fromEmail;
$Campaign->fromAddress = $fromEmail;
$Campaign->replyAddress = $replyEmail;
$CampaignsCollection = new CampaignsCollection($this->CTCTRequest);
return $CampaignsCollection->addCampaign($Campaign);
}

 

that i am unable to get it, same is with adding contact and adding a list to the campaign.

3 REPLIES 3
CTCT Employee

Re: How can i create email campaign and email list and add contacts to that list using PHP wrapper

Hi,

 

These are going to be handled as two separate requests:  adding contacts to a list, and creating a campaign (assigning a list to the campaign at the same time).  We have an example of how to create a campaign using the wrapper here.  

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Contributor

Re: How can i create email campaign and email list and add contacts to that list using PHP wrapper

Thanks for your reply, and how will i be able to add contact list to this following campaign and contact to this contact list of this campaign.

CTCT Employee

Re: How can i create email campaign and email list and add contacts to that list using PHP wrapper

Hi,

 

For adding acontact to your lists, you'll want to do that separately, probably before creating and scheduling your email through the API.  Here is how I personally add contacts to lists.  In this example I'm adding contacts to contact list 1 (my General Interest list).  There are a fair amount of echo statements that you can remove.

 

<?php

session_start ();
require_once 'ConstantContact.php';
require_once 'config.php';

$ConstantContact = new ConstantContact("oauth2", $apiKey, $username, $accessToken);

// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50

// Email address here is used for testing purposes
// NOTE:  This email address will be added to your account if you execute this script,
//		  you should send this to do-not-mail after your testing
$emailAddress = "testemail10312012@test.com";

// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);
echo '<pre>';
print_r($ConstantContact);
echo '</pre>';
echo $emailAddress . "<br>";
//echo $ContactsCollection->searchContactsByEmail($ext);

// If the search didnt return a contact object
if($search == false)
{
	// Create a new Contact Object to store data into
	$contactObj = new Contact();
	// Adding multiple lists to this new Contact Object
	$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
	// Set the email address
	$contactObj->emailAddress = $emailAddress;
	// Create the Contact and DONE
	$Contact = $ConstantContact->addContact($contactObj);
	echo ("Contact added.");

} // Otherwise we update our existing
else 
{
	// Gather data from our previous search and store it into a data type
	$contactObj = $ConstantContact->getContactDetails($search[0]);

	// We need to get the old list and add a new list to it as
	// this request requires a PUT and will remove the lists
	// as they are stored in an array
	 array_push($contactObj->lists, $lists['lists'][1]->id );
	
	// Update the contact and DONE
	$UpdateContact = $ConstantContact->updateContact($contactObj);
	echo ("Contact updated.");
}

?>	

 

As for assigning lists to email campaigns, that is handled around line 97 in the link I referenced before.

 

Best Regards,

Shannon W.

API Support Specialist