Hi,
I have the case of wanting to send a reader some free content in return for them signing up to my mailing list. fairly standard stuff. For that to work smoothly, with a minimal number of emails sent, I want the email I send through Drupal with the links to the content, to also be the double opt in confirmation. i.e. if you click on the content link, that's your double confirmation. I don't want mail chimp to send out a confirmation email, and then have to send out another email with the content links, and then have to check if the reader has confirmed subscription yet. So, here's what I did to the mailchimp_subscribe_user() function:
function _mailchimp_subscribe_user($list, $email, $merge_vars, $message = TRUE, $q = NULL, $sub_ops=array()) {
if ($q || $q = _mailchimp_get_api_object()) {
$double_optin = $list->doublein;
$default_sub_ops = array('double_optin' => $double_optin, 'email_type' => 'html', 'update_existing' => TRUE);
$default_merge_vars = array('OPTIN_TIME' => date('YYYY-MM-DD HH:ii:ss'), 'OPTIN_IP' => ip_address());
$merge_vars = $merge_vars + $default_merge_vars;
$sub_ops = $sub_ops + $default_sub_ops;
// required by MC API. An empty array will fail.
if (empty($merge_vars)) {
$merge_vars = '';
}
if (_mailchimp_is_subscribed($list->id, $email, $q)) {
$action = 'updated in';
$success = $q->listUpdateMember($list->id, $email, $merge_vars);
if($success && $message){
drupal_set_message(t('You have updated your settings in %list.', array('%list' => $list->name)));
}
}
else {
$action = 'subscribed to';
$success = $q->listSubscribe($list->id, $email, $merge_vars, $sub_ops['email_type'], $sub_ops['double_optin'], $sub_ops['update_existing']);
...
(The same approach can also be used to allow the setting of the other mailchimp API options for subscription.)
Comments
Comment #1
nrackleff commented“And now our watch [for support of the 6.x version of the MailChimp module] has ended…” With the end of Drupal 6 support, I’m sad to say we too must turn the page.
Fret not! The 7.x-4.x and 8.x versions come highly recommended. Both are using Mailchimp’s new API 3.0 and are being actively maintained. “What is dead may never die, but rises again, harder and stronger!”