1-866-284-2541  |  Registered Users LOGIN 

MailChimp Home Learn More Pricing Resource Center Blog Free Trial

MailChimp API
Back to Documentation Overview

campaignCreate

public static campaignCreate(string uid, string list_id, string subject, string from_email, string from_name, array content, integer template_id, array tracking, boolean authenticate, string analytics, string title)

Create a new draft campaign to send


Section:
Campaign Related

Parameters:
uid the id for your user account. Get by calling login($user, $pass)
list_id the list to send this campaign to- get lists using getLists()
subject the subject line for your campaign message
from_email the From: email address for your campaign message
from_name the From: name for your campaign message
content the content for this campaign - use a struct with the following keys: "html" for pasted HTML content and "text" for the plain-text version. If you chose a template instead of pasting in your HTML content, then use "html_" followed by the template sections as keys - for example, use a key of "html_MAIN" to fill in the "MAIN" section of a template. Supported template sections include: "html_HEADER", "html_MAIN", "html_SIDECOLUMN", and "html_FOOTER"
template_id optional - use this template to generate the HTML content of the campaign
tracking optional - set which recipient actions will be tracked, as a struct of boolean values with the following keys: "opens", "html_clicks", and "text_clicks". By default, opens and HTML clicks will be tracked.
title optional - an internal name to use for this campaign. By default, the campaign subject will be used.
authenticate optional - set to true to enable SenderID, DomainKeys, and DKIM authentication, defaults to false
analytics optional - if provided, use a struct with "service type" as a key and the "service tag" as a value. For Google, this should be "google"=>"your_google_analytics_key_here". Note that only "google" is currently supported - a Google Analytics tags will be added to all links in the campaign with this string attached. Others may be added in the future

Returns:
string   -  the ID for the created campaign

Examples (2)

[1] mcapi_campaignCreate.php

  1. <?php
  2. /**
  3. This Example shows how to Create a Campgaign using the MCAPI.php class using
  4. a template to set custom content sections and do some basic error checking.
  5. **/
  6.  
  7. // Include the MailChimp API code. Do Not Edit This!
  8. include('inc/MCAPI.class.php');
  9. include('config.inc');
  10.  
  11. // Connect to the MailChimp server with the user's credentials.
  12. $acct = new MCAPI($mailChimpUser, $mailChimpPass);
  13.  
  14. $list_id = 'XXXXXXXX';
  15.  
  16. $subject = 'My Newsletter Test';
  17. $title = 'Test - newsletter';
  18. $from_email = 'coyote@acmeinc.org';
  19. $from_name = 'ACME, Inc.';
  20. //Note: the 4 "html_" section values shown are the only ones supported
  21. $content = array('html_main'=>'some pretty html content',
  22. 'html_sidecolumn' => 'this goes in a side column',
  23. 'html_header' => 'this gets placed in the header',
  24. 'html_footer' => 'the footer with an *|UNSUB|* message',
  25. 'text' => 'text content text content *|UNSUB|*'
  26. );
  27. $template_id = "1";
  28.  
  29. $tracking=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);
  30.  
  31. $authenticate = false;
  32. $analytics = array('google'=>'my_google_analytics_key');
  33.  
  34. $cid = $acct->campaignCreate($list_id, $subject, $from_email, $from_name,
  35. $content, $template_id, $tracking, $title,
  36. $authenticate, $analytics);
  37. if (!$cid){
  38. echo "Unable to load campaignCreate()!\n";
  39. echo "\tCode=".$acct->errorCode."\n";
  40. echo "\tMsg=".$acct->errorMessage."\n";
  41. } else {
  42. echo "New Campaign ID: = ".$cid;
  43. }
  44.  
  45. ?>
  46.  

[2] xml-rpc_createCampaign.php

  1. <?php
  2. /**
  3. This Example shows how to use the XML-RPC service to create a new Campaign
  4. and do some basic error checking.
  5. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. include('inc/config.inc.php'); //contains username & password
  9.  
  10. $client = XML_RPC2_Client::create($apiUrl);
  11. $uuid = $client->login($username,$password);
  12.  
  13. $subject = 'My Newsletter Test';
  14. $title = 'Test - newsletter';
  15. $from_email = 'coyote@acmeinc.org';
  16. $from_name = 'ACME, Inc.';
  17. $content = array('html'=>'some pretty html content *|UNSUB|* message',
  18. 'text' => 'text text text *|UNSUB|*'
  19. );
  20. $template_id = "";
  21.  
  22. $tracking=array('opens' => true, 'html_clicks' => true, 'text_clicks' => true);
  23.  
  24. $authenticate = false;
  25. $analytics = array('google'=>'my_google_analytics_key');
  26.  
  27. try {
  28. //parameters wrapped to fit the page...
  29. $result = $client->campaignCreate($uuid, $list_id, $subject, $from_email, $from_name,
  30. $content, $template_id, $tracking, $title,
  31. $authenticate, $analytics);
  32. echo "SUCCESS! \n";
  33. var_dump($result);
  34. } catch (XML_RPC2_FaultException $e){
  35. echo "ERROR!!!!\n";
  36. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  37. }
  38. ?>
  39.  
Add New Note User Contributed Notes
campaignCreate
No notes, yet... Will you be the first??

Email Marketing Resources  |   Free HTML Email Templates  |   Partners  |  Find an Expert  |   Add-ons  |   API  |   Plugins  |   Blog  |  Demos  |  Surveys  |   Webinars  |   Subscribe to our free Email Marketing Tips Newsletter

New Features:  RSS to Email  |   A/B Split Testing Emails  |   Google Analytics Integration  |   Segmentation

Truste Certified Privacy Click to verify BBB accreditation and to see a BBB report ESPC Members MAAWG Email Experience Council Members HACKER SAFE certified sites prevent over 99.9% of hacker crime.
WebAward Winner W3 Award Webby Award Nominee As featured on MSNBC's Your Business Program