« Back to Documentation Overview
listSubscribe – v1.3
listSubscribe(string apikey, string id, string email_address, array merge_vars, string email_type, bool double_optin, bool update_existing, bool replace_interests, bool send_welcome)
Subscribe the provided email to a list. By default this sends a confirmation email - you will not see new members until the link contained in it is clicked!
- <?php
- /**
- This Example shows how to Subscribe a New Member to a List using the MCAPI.php
- class and do some basic error checking.
- **/
- require_once 'inc/MCAPI.class.php';
- require_once 'inc/config.inc.php'; //contains apikey
- 'GROUPINGS'=>array(
- )
- );
- // By default this sends a confirmation email - you will not see new members
- // until the link contained in it is clicked!
- $retval = $api->listSubscribe( $listId, $my_email, $merge_vars );
- if ($api->errorCode){
- } else {
- }
- ?>
- <?php
- require_once 'inc/config.inc.php'; //contains apikey
- 'address1'=>array('addr1'=>'12335 Hope St', 'city'=>'Dallas', 'state'=>'TX', 'zip'=>'76058'),
- 'phone' => '412392222522255',
- 'MMERGE5'=>'http://www.mailchimp.com/',
- 'OPTIN_IP'=>'8.8.4.4',
- 'GROUPINGS'=>array(
- ),
- 'MC_LOCATION'=>array('LATITUDE'=>34.0413, 'LONGITUDE'=>-84.3473)
- );
- $double_optin=true;
- $update_existing=false;
- $replace_interests=true;
- $send_welcome=false;
- $email_type = 'html';
- 'email_address'=>$email,
- 'apikey'=>$apikey,
- 'merge_vars' => $merges,
- 'id' => $listId,
- 'double_optin' => $double_optin,
- 'update_existing' => $update_existing,
- 'replace_interests' => $replace_interests,
- 'send_welcome' => $send_welcome,
- 'email_type' => $email_type
- );
- $payload = json_encode($data);
- //replace us2 with your actual datacenter
- $submit_url = "http://us2.api.mailchimp.com/1.3/?method=listSubscribe";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $submit_url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true);
- $result = curl_exec($ch);
- curl_close ($ch);
- $data = json_decode($result);
- if ($data->error){
- } else {
- }
- ?>
- <?php
- /**
- This Example shows how to Subscribe a New Member to a List using XML-RPC.
- Note that we are using the PEAR XML-RPC client and recommend others do as well.
- **/
- require_once 'XML/RPC2/Client.php';
- require_once 'inc/config.inc.php';
- try {
- // Note that the same blank array() restriction for the merge_vars
- // does not apply here as XML-RPC will handle it unless you use a null value
- 'INTERESTS'=>'Dogs,Horses');
- // By default this sends a confirmation email - you will not see new members
- // until the link contained in it is clicked!
- $result = $client->listSubscribe($apikey, $listId, $my_email, $merges, 'html', false);
- } catch (XML_RPC2_FaultException $e){
- }
- ?>
| Section | List Related |
|---|
| Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| apikey | a valid API Key for your user account. Get by visiting your API dashboard | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id | the list id to connect to. Get by calling lists() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| email_address | the email address to subscribe | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| merge_vars | optional - merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). Note that a merge field can only hold up to 255 bytes. Also, there are a few "special" keys:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| email_type | optional - email type preference for the email (html or text - defaults to html) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| double_optin | optional - flag to control whether a double opt-in confirmation message is sent, defaults to true. Abusing this may cause your account to be suspended. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_existing | optional - flag to control whether existing subscribers should be updated instead of throwing an error, defaults to false | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| replace_interests | optional - flag to determine whether we replace the interest groups with the groups provided or we add the provided groups to the member's interest groups (optional, defaults to true) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| send_welcome | optional - if your double_optin is false and this is true, we will send your lists Welcome Email if this subscribe succeeds - this will *not* fire if we end up updating an existing subscriber. If double_optin is true, this has no effect. defaults to false. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns | |
|---|---|
| boolean | true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below) |
Examples (3)
download example code[1] mcapi_listSubscribe.php
[2] json_listSubscribe.php
[3] xml-rpc_listSubscribe.php