Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Welcome Email when using Mailchimp API 3 List/Member Method

Is there a way to send the Mailchimp Welcome Email when using Mailchimp API 3 List/Member method? Older API implementations can do it without the need for Automation (paid feature), but I am not sure if API 3 supports it in List/Member method. I am referring to emails that users usually get when they sign up using a standard Mailchimp form.

For instance, this script will not send a Welcome email or any other post-sign up Mailchimp emails.

$apikey = '<api_key>'; 
$auth = base64_encode( 'user:'.$apikey );

$data = array(
       'apikey'        => $apikey,
        'email_address' => $email,
        'status'        => 'subscribed',
        'merge_fields'  => array(
        'FNAME' => $name
            )
);
$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://us2.api.mailchimp.com/3.0/lists/<list_id>/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);                                                                                                                  

$result = curl_exec($ch); 
var_dump($result);
die('Mailchimp executed');
like image 468
Edville Avatar asked Aug 27 '15 07:08

Edville


People also ask

How do I change the final welcome email in Mailchimp?

Click the Manage Audience drop-down and choose Signup forms. Select Form builder. Click the Forms and response emails drop-down menu, and choose Final welcome email. Check the box next to Send a final welcome email to turn the final welcome email on, or uncheck the box to turn it off.


2 Answers

It is very simple: Make sure to turn on the final welcome email in the list settings.

When executing the request set the status to pending. The user wil receive an welcome email in a few minutes.

$data = array(
    'apikey'        => $apikey,
    'email_address' => $email,
    'status'        => 'pending'
);
like image 155
Robin Avatar answered Sep 28 '22 08:09

Robin


If you turn on the final welcome email for your list it should send when you subscribe. There's currently no way to override the list setting in API v3.0.

like image 26
TooMuchPete Avatar answered Sep 28 '22 09:09

TooMuchPete