This function adds a new email to existing list with all additional values of the field.
listSubscribe(string $id, string $email_address, array $merge_vars, string $email_type, boolean $double_optin, boolean $update_existing, boolean $send_welcome) : boolean
Array of merge fields. Each merge field is represented as an array that includes:
/** * This Example shows how to listSubscribe using the MGAPI.php class and do some basic error checking. */ require_once 'inc/MGAPI.class.php'; require_once 'inc/config.inc.php'; //contains apikey $api = new MGAPI($apikey); $id = $listId; $email_address = $my_email; $merge_vars = array('EMAIL' => $my_email, 'FNAME' => 'Joe'); // or $merge_vars = array(''); $email_type = 'html'; $double_optin = true; $update_existing = false; $send_welcome = false; $retval = $api->listSubscribe($id, $email_address, $merge_vars, $email_type, $double_optin, $update_existing, $send_welcome); header("Content-Type: text/plain"); if ($api->errorCode) { echo "Unable to load listSubscribe()!\n"; echo "\tCode=" . $api->errorCode . "\n"; echo "\tMsg=" . $api->errorMessage . "\n"; } else { echo "Returned: " . $retval . "\n"; }
/** * This Example shows how execute a listSubscribe and check the result using XML-RPC. * Note that we are using the PEAR XML-RPC client and recommend others do as well. */ require_once 'xmlrpc-3.0.0.beta/xmlrpc.inc'; require_once 'inc/config.inc.php'; $apiUrl = parse_url($apiUrl); $v = new xmlrpcval(array( 'apikey' =--> new xmlrpcval($apikey), 'id' => new xmlrpcval($listId), 'email_address' => new xmlrpcval($my_email), 'merge_vars' => php_xmlrpc_encode( array('EMAIL' => $my_email, 'FNAME' => 'Joe') ), 'email_type' => new xmlrpcval('html'), 'double_optin' => new xmlrpcval(true), 'update_existing' => new xmlrpcval(false), 'send_welcome' => new xmlrpcval(false) ), 'struct'); $f = new xmlrpcmsg('listSubscribe', array($v)); $c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80); $c->setDebug($debug); $r = &$c->send($f); header("Content-Type: text/plain"); if (!$r->faultCode()) { $retval = php_xmlrpc_decode($r->value()); echo "Returned: " . $retval . "\n"; } else { echo "Unable to load listSubscribe()!\n"; echo "\tCode=" . $r->faultCode() . "\n"; echo "\tMsg=" . $r->faultString() . "\n"; }
from lib.config import * #contains apikey from lib.MGAPI import MGAPI # This Example shows how to ping using the MGAPI.php class and do some basic error checking. api = MGAPI(apikey) id = listId email_address = my_email merge_vars = {'EMAIL': my_email, 'FNAME': 'Joe'} # or merge_vars = {} email_type = 'html' double_optin = True update_existing = False send_welcome = False retval = api.listSubscribe(id, email_address, merge_vars, email_type, double_optin, update_existing, send_welcome) if api.errorCode: print "Unable to load listSubscribe()!" print "\tCode=", api.errorCode print "\tMsg=", api.errorMessage else: print "Returned: ", retval