Skip to content

Instantly share code, notes, and snippets.

@ricardo-rossi
Created September 18, 2014 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardo-rossi/d548d2b3421b1b7a9c09 to your computer and use it in GitHub Desktop.
Save ricardo-rossi/d548d2b3421b1b7a9c09 to your computer and use it in GitHub Desktop.
This class handles adding new users our MailChimp mailing list as well as updating the list entry based on actions
<?php namespace Endata\Lists;
use MailChimp;
use Carbon\Carbon;
class MailingList {
protected $mailchimp;
protected $list_id = 'MCIDXXX'; // The MailChimp list id
/*
* Constructor initializes MailChimp API using the unique API key
*/
public function __construct()
{
$this->mailchimp = new \Mailchimp('MCAPIKEY');
}
/**
* Subscribe a user to a Mailchimp list
*
* @param [type] $email [description]
* @param [type] $fname [description]
* @param [type] $lname [description]
* @param [type] $country [description]
* @param [type] $company [description]
* @param [type] $type [description]
* @param [type] $phone [description]
* @return [type] [description]
*/
public function subscribe($email, $fname, $lname, $country, $company, $type, $phone)
{
$vars = array
(
'FNAME' => $fname,
'LNAME' => $lname,
'COUNTRY' => $country,
'COMPANY' => $company,
'TYPE' => $type,
'PHONE' => $phone,
'SIGNED' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [free_start description]
* @param [type] $email [description]
* @return [type] [description]
*/
public function free_start($email)
{
$vars = array
(
'FREE_START' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [solo_start description]
* @param [type] $email [description]
* @return [type] [description]
*/
public function solo_start($email)
{
$vars = array
(
'SOLO_START' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [solo_trial description]
* @param [type] $email [description]
* @return [type] [description]
*/
public function solo_trial($email)
{
$vars = array
(
'SOLO_TRIAL' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [team_start description]
* @param [type] $email [description]
* @return [type] [description]
*/
public function team_start($email)
{
$vars = array
(
'TEAM_START' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [team_trial description]
* @param [type] $email [description]
* @return [type] [description]
*/
public function team_trial($email)
{
$vars = array
(
'TEAM_TRIAL' => Carbon::now('GMT')->toDateString()
);
return $this->send($email, $vars);
}
/**
* [send description]
*
* @param [type] $email [description]
* @param [type] $vars [description]
* @return [type] [description]
*/
private function send($email, $vars)
{
$data = array(
'id' => $this->list_id,
'email' => array('email'=> $email),
'merge_vars' => $vars,
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false
);
return $this->mailchimp->call('lists/subscribe', $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment