I am looking to use Constant Contacts API in PHP to create an email campaign to send to people telling them a daily bible reading is ready for them at my church's daily Bible reading site and then schedule it.
Eventually I would like to mail the actual reading once I customize the site more.
I've read a number of posts and pages looking to get started and have no idea where to begin.
I've seen talk about a wrapper, but have no idea what it is or how to put it in place?
I know I want to initiate a POST but the formats I've seen don't look familair to me.
I use Bluehost for my hosting company. From what I can see they do not offer Curl with PHP.
Can some one please step me through this.
Thanks in advance.
Solved! Go to Solution.
You're actually very close. That error message is just letting you know that the email content needs to be wrapped in html and body tags, ie:
<html><body>This is my HTML content</body></html>
The form in the example is just meant as a demonstration of how one could create and schedule an email campaign. You can pull out portion of the code that actually does the creation and do without the entire form if that's what suits your needs.
You can certainly create and schedule an email campaign through our API. We have sample code and wrapper libraries for PHP (requires PHP 5.3+ and cURL to be enabled). You can find them here: http://developer.constantcontact.com/libraries/sample-code.html
Documentation on using Email Campaigns through the API, which are all custom HTML code based, can be found here: http://developer.constantcontact.com/docs/email-campaigns/email-campaign-api-index.html
Thanks for responding. I am running PHP 5.4.27 with cURL enabled. So that's not a problem. Last night I went out and I think I found and downloaded the wrapper whch was in a zip file named php-sdl-master.zip. Let me know if that is the correct. Even if it is, I'm not sure what to do with it as in where to unzip it to. For example, I host multiple sites. This particular one is using WordPress. Do they go in the highest directory of the hosted site or some other? I'm presuming that the wrapper needs to be in place to move forward with the rest.
Thanks again for your assistance.
The wrapper library gives PHP functions and objects for our v2 JSON REST API. Basically, it gives you building blocks to make an integration that does just about anything you can think of with our API.
It doesn't matter where on the server it's installed, as long as you have the include paths set up to reflect where it is installed in your php files. At this point, you'll be able to make a new Wordpress module or functions using our API. This is where it becomes a custom development project for you. Unfortunately, we don't support developing in other frameworks like Wordpress, only questions on our API.
Thanks for the update. So that zip file was the correct one?
If that's so, I'll download it into the client site just to make deployment easie and less confused.Then begin interacting with the information in the URL's you provided.
Just to be clear, the construction of the email is being done in all PHP using MySQL and not in WordPress
There are already plugins available in WordPress for creating sign ups and granting access to lists, which is where the integration would take place if any. I may just provide a link to the sign up created in Constant Contact itself.
From my experience, it will be much easier for you to develop using straight PHP and MySQL. Our wrapper doesn't contain anything for integrating directly with a database, but it should be pretty easy for you to map your MySQL data to our PHP objects and then create campaigns. Let us know if you have any questions about the wrapper.
The immediate goal of this project is to simply create and email in Constant Contact that can be sent to an existing list, which holds the email addressed of people looking to receive an email daily pointing them to a WordPress page which has a Daily Bible Reading for the plan they have subscribed to. So the content of the email is simple and will contain a URL.
The next step is to use php and MySQL databases to determine the particular passage for the daily reading, issue the API REST call to retrieve that data and then use it as the content in the email.
So right now I just have to learn how to create the email and schedule it. I'll build upon that later my just substituting in the next content.
It would appear that installing the wrapper would be the easiest way to go, correct? Could you please verify I have the correct file? I included the name in a previous email.
I've downloaded the wrapper and expanded it in the directory where the source PHP code resides.
Then I copied the code from the example into the source directory and executed it.
I got the following error:
[23-Apr-2014 05:29:50 America/Denver] PHP Fatal error: Uncaught exception 'Ctct\Exceptions\IllegalArgumentException' with message 'Only an id or ContactList object are allowed for this method.' in /home1/zeebsweb/public_html/biblereading/php_snippets/php-sdk-master/src/Ctct/Components/EmailMarketing/Campaign.php:289
#0 /home1/zeebsweb/public_html/biblereading/php_snippets/cc.php(56): Ctct\Components\EmailMarketing\Campaign->addList(Array)
#1 /home1/zeebsweb/public_html/biblereading/php_snippets/cc.php(79): createCampaign(Array)
thrown in /home1/zeebsweb/public_html/biblereading/php_snippets/php-sdk-master/src/Ctct/Components/EmailMarketing/Campaign.php on line 289
From the code it appears to be a problem with the contact list. I simply chose one presented in the drop down list from the form. I tried to different ones. Both through the same exception.
Not sure what the problem is here.
It's hard to say what exactly the problem is, but I did just successfully test this so I do not believe it is an issue wih the library.
You should be able to download a zip from: https://github.com/constantcontact/php-sdk/archive/master.zip
You can extract this zip into your web root, which by default will probably make a folder called 'php-sdk-master' (but you can rename this to whatever you want). Then you would want to modify php-sdk-master/examples/createAndScheduleCampaign.php (lines 31 & 32) to add your apikey/access token:
// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "ENTER YOUR API KEY");
define("ACCESS_TOKEN", "ENTER YOUR ACCESS TOKEN");
You can then hit /examples/createAndScheduleCampaign.php in your broswer and properly run the example.
View API documentation, code samples, get your API key.
We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...Read More