Back to Documentation Overview

listSubscribe

public static listSubscribe(string uid, string id, string email_address, array merge_vars, string email_type, boolean double_optin)

Subscribe the provided email to a list

Section:
List Related
Parameters:
uid the id for your user account. Get by calling login($user, $pass)
id the list id to connect to
email_address the email address to subscribe
merge_vars array of merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). Set Interest Groups by passing a field named "INTERESTS" that contains a comma delimited list of Interest Groups to add.
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
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 (2)

download example code

[1] mcapi_listSubscribe.php

  1. <?php
  2. /**
  3. This Example shows how to Subscribe a New Member to a List using the MCAPI.php
  4. class and do some basic error checking.
  5. **/
  6. // Include the MailChimp API code. Do Not Edit This!
  7. include('inc/MCAPI.class.php');
  8. include('inc/config.inc.php'); //contains username & password
  9.  
  10. // Connect to the MailChimp server with the user's credentials.
  11. $acct = new MCAPI($mailChimpUser, $mailChimpPass);
  12.  
  13. /**
  14. Note that if you are not passing merge_vars, you will still need to
  15. pass a "blank" array. That should be either:
  16. $merge_vars = array('');
  17. - or -
  18. $merge_vars = '';
  19.  
  20. Specifically, this will fail:
  21. $merge_vars = array();
  22.  
  23. Or pass the proper data as below...
  24. */
  25. $merge_vars = array('FNAME'=>'Test', 'LNAME'=>'Account');
  26.  
  27. $retval = $acct->listSubscribe( $listId, $new_email, $merge_vars );
  28.  
  29. if (!$retval){
  30. echo "Unable to load listSubscribe()!\n";
  31. echo "\tCode=".$acct->errorCode."\n";
  32. echo "\tMsg=".$acct->errorMessage."\n";
  33. } else {
  34. //do something useful!
  35. var_dump($retval);
  36. }
  37.  
  38. ?>
  39.  

[2] xml-rpc_listSubscribe.php

  1. <?php
  2. /**
  3. This Example shows how to Subscribe a New Member to a List using the XML-RPC service
  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. try {
  14. // Note that the same blank array() restriction does apply here that
  15. // applied to the MCAPI example
  16. $result = $client->listSubscribe($uuid, $listId, $new_email ,array(), 'html', false);
  17. echo "SUCCESS!\n";
  18. var_dump($result);
  19. } catch (XML_RPC2_FaultException $e){
  20. echo "ERROR!!!!\n";
  21. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  22. }
  23. ?>
  24.  
Add New Note User Contributed Notes for listSubscribe
No notes, yet... Will you be the first??