listSubscribe()

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
Input parametrs
  • id - list ID
  • email_address - address of added email
  • merge_vars - values of merge fields (array)
  • Merge fields are: FNAME, LNAME, EMAIL and other your defined fields.
  • email_type - type of email (HMTL, plain) (optional). Default value is HTML.
  • double_optin - whether confirmation email is sent (true, false) (optional). Default value is true.
  • update_existing - whether existing emails are restored (true, false) (optional). Default value is false.
  • send_welcome - whether ‘Thank you’ email is sent (true, false) (optional). Default value is false.

Array of merge fields. Each merge field is represented as an array that includes:

  • true, if request for adding new email has succeeded.

Examples

mgapi_listSubscribe.php
/**
 * 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";
}
xml-rpc_listSubscribe.php
/**
 * 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";
}
mgapi_listSubscribe.py
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

© 2010-2017 Mailigen. All rights reserved.