-
Notifications
You must be signed in to change notification settings - Fork 0
/
eform2mailchimp.php
47 lines (38 loc) · 1.67 KB
/
eform2mailchimp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
function eForm2mailchimp( &$fields )
{
/*---------------------------------------------------------------
eForm2mailchimp
Version: 0.1
Author: digitalime
---------------------------------------------------------------
Requirements:
eForm 1.4+
MailChimp API by drewm github.com/drewm/mailchimp-api/
---------------------------------------------------------------
---------------------------------------------------------------*/
// Bring needed resources into scope
global $modx;
include('assets/snippets/eform2mailchimp/MailChimp.php');
$listid = $modx->db->escape($fields[listid]);
$apikey = "APIKEY HERE"; //From https://admin.mailchimp.com/account/api/
// Grab the values from the form
$firstname = $modx->db->escape($fields[firstname]);
$lastname = $modx->db->escape($fields[lastname]);
$email = $modx->db->escape($fields[email]);
$organisation = $modx->db->escape($fields[organisation]);
$tel = $modx->db->escape($fields[tel]);
//Let's call the Maichimp API and send the stuff
$MailChimp = new \Drewm\MailChimp($apikey);
$result = $MailChimp->call('lists/subscribe', array(
'id' => $listid, //SET THIS AS A HIDDEN FIELD IN YOUR FORM,
'email' => array('email'=>$email),
'merge_vars' => array('FNAME'=>$firstname, 'LNAME'=>$lastname, 'ORGA'=>$organisation, 'TEL'=>$tel ),
'double_optin' => true,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
));
}
return false;
?>