verax
verax

Reputation: 173

Mailchimp add name

i'm trying to add a new user to my list on mailchimp (email, first name and last name). But i've could not, any help would be apreciated.

my variables:

$email = test_input($_POST["email"]);
$name = test_input($_POST["name"]);
$arr = explode(' ',trim($nombre));

included Mailchimp api v2.0

include('Path/to/Mailchimp.php');

$api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxx"; 
$list_id = "xxxxxxxxxx";
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );

then, after some steps i try to subscribe a new user to my list:

try {
    $subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $email)); 
} catch (Exception $e) {
}

but, when i try to change to:

$subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $email, 'FNAME'=>'Test', 'LNAME'=>'Account' ));

Nothing happens.

Upvotes: 1

Views: 2002

Answers (1)

verax
verax

Reputation: 173

solved it! by adding the missing parameters

try {
$merge_vars = array("FNAME"=>$arr[0],"LNAME"=>$arr[1],);
$double_optin = FALSE;
        $subscriber = $Mailchimp_Lists->subscribe( $list_id, array( 'email' => $email), $merge_vars,'html',$double_optin ); 
    } catch (Exception $e) {
      echo $e;
    }

Upvotes: 2

Related Questions