Автор: Drew McLellan (drew.mclellan@gmail.com)
<?php

echo "hello";
include 'MailChimp.php';
use DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('8daa36240ea1db9c35580a95c534c55b-us12');
$list_id = '99a9b4b2d4';
$result = $MailChimp->post("lists/{$list_id}/members", ['email_address' => '*****@*****.**', 'status' => 'subscribed']);
print_r($result);
// $fname = mysql_escape_string($_POST['first_name']);
// $lname = mysql_escape_string($_POST['last_name']);
// $email = mysql_escape_string($_POST['email']);
// $title = mysql_escape_string($_POST['title']);
//
// if(strlen($title) > 0){
//   header('HTTP/1.1 401 Unauthorized');
//   exit;
// }else{
//   $MailChimp = new \Drewm\MailChimp('867cf1372a079e8f588fc974482af793-us10');
//   $result = $MailChimp->call('lists/subscribe', array(
//     'id'                => 'f0f1e0de59',
//     'email'             => array('email'=>$email),
//     'merge_vars'        => array('FNAME'=>$fname, 'LNAME'=>$lname),
//     'double_optin'      => false,
//     'update_existing'   => true,
//     'replace_interests' => false,
//     'send_welcome'      => false,
//   ));
//
//   if($result){
//     header('HTTP/1.1 200 Success');
Пример #2
1
<?php

require "../vendor/autoload.php";
use DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('255970dd153fe7b1d83bec1478cbaa74-us11');
$result = $MailChimp->get('lists');
// Mailing List
// $list_id = '5c6bd183d4';
// Simpleblend Blog
$list_id = '53f4059701';
$result = $MailChimp->post("lists/{$list_id}/members", ['email_address' => '*****@*****.**', 'status' => 'subscribed']);
if ($MailChimp->success()) {
    print_r($result);
} else {
    echo $MailChimp->getLastError();
}
// require_once 'inc/MCAPI.class.php';
// $api = new MCAPI('[[YOUR_API_KEY]]');
// $merge_vars = array('FNAME'=>$_POST["fname"], 'LNAME'=>$_POST["lname"]);
//
// // Submit subscriber data to MailChimp
// // For parameters doc, refer to: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
// $retval = $api->listSubscribe( '[[YOUR_LIST_ID]]', $_POST["email"], $merge_vars, 'html', false, true );
//
// if ($api->errorCode){
//   echo "<h4>Please try again.</h4>";
//
// } else {
//   echo "<h4>Thank you, you have been added to our mailing list.</h4>";
//
// }
 /**
  * Process our Push notification
  *
  * @access public
  * @since  0.0.1
  * @return void
  */
 public function process($id)
 {
     $form_id = $id ? Ninja_Forms()->notification($id)->form_id : '';
     $api_key = Ninja_Forms()->notification($id)->get_setting('api_key');
     $list_id = Ninja_Forms()->notification($id)->get_setting('list_id');
     $email = $this->process_setting($id, 'email');
     if (empty($api_key) || empty($list_id) || empty($email)) {
         //file_put_contents('/tmp/notifications-pushbullet-class.log', "Empty access token\n", FILE_APPEND);
         return;
     }
     $first_name = $this->process_setting($id, 'first_name');
     $last_name = $this->process_setting($id, 'last_name');
     $merge_fields = array();
     if ($first_name) {
         $merge_fields['FNAME'] = $first_name;
     }
     if ($last_name) {
         $merge_fields['LNAME'] = $last_name;
     }
     $mc = new MailChimp($api_key);
     $added = $mc->post("lists/{$list_id}/members", array('email_address' => $email, 'status' => 'subscribed', 'merge_fields' => $merge_fields));
     if ($added) {
         //
     } else {
         // Could be SSL-verify of cURL that fails...
     }
 }
 public function import_content(\DrewM\MailChimp\MailChimp $MailChimpAPI)
 {
     // import content
     $campaignID = $this->campaignMailChimpID();
     $content = $MailChimpAPI->get("campaigns/{$campaignID}/content");
     if ($MailChimpAPI->success()) {
         $this->update(['campaignText' => $content['plain_text'], 'campaignHTML' => $content['html']]);
     }
 }
Пример #5
0
 public function testNewBatch()
 {
     $MC_API_KEY = getenv('MC_API_KEY');
     if (!$MC_API_KEY) {
         $this->markTestSkipped('No API key in ENV');
     }
     $MailChimp = new MailChimp($MC_API_KEY);
     $Batch = $MailChimp->new_batch();
     $this->assertInstanceOf('DrewM\\MailChimp\\Batch', $Batch);
 }
Пример #6
0
 public function testGetLists()
 {
     $MC_API_KEY = getenv('MC_API_KEY');
     if (!$MC_API_KEY) {
         $this->markTestSkipped('No API key in ENV');
     }
     $MailChimp = new MailChimp($MC_API_KEY);
     $lists = $MailChimp->get('lists');
     $this->assertArrayHasKey('lists', $lists);
 }
Пример #7
0
 public function testSubscriberHash()
 {
     $MC_API_KEY = getenv('MC_API_KEY');
     if (!$MC_API_KEY) {
         $this->markTestSkipped('No API key in ENV');
     }
     $MailChimp = new MailChimp($MC_API_KEY);
     $email = '*****@*****.**';
     $expected = md5(strtolower($email));
     $result = $MailChimp->subscriberHash($email);
     $this->assertEquals($expected, $result);
 }
 /**
  * Fetches a list of email templates from MailChimp.
  *
  * @param MailChimp $mailChimp
  * @return ArrayList
  */
 public function getMailChimpTemplates($mailChimp)
 {
     $templates = ArrayList::create();
     $response = $mailChimp->get('templates');
     if (!$mailChimp->success()) {
         $message = $response && array_key_exists($response['errors']) ? $response['errors'][0]['message'] : 'Error connecting to MailChimp API';
         user_error($message, E_USER_ERROR);
     }
     foreach ($response['templates'] as $template) {
         if ($template['type'] == 'user') {
             $templates->push(ArrayData::create($template));
         }
     }
     $this->extend('updateMailChimpTemplates', $templates);
     return $templates;
 }
 /**
  * Process our Push notification
  *
  * @access public
  * @since  0.0.1
  * @return void
  */
 public function process($id)
 {
     $form_id = $id ? Ninja_Forms()->notification($id)->form_id : '';
     $api_key = Ninja_Forms()->notification($id)->get_setting('api_key');
     $list_id = Ninja_Forms()->notification($id)->get_setting('list_id');
     $email = $this->process_setting($id, 'email');
     $subscribe = $this->process_setting($id, 'subscribe');
     if ('checked' != $subscribe) {
         return;
     }
     if (empty($api_key) || empty($list_id) || empty($email)) {
         //file_put_contents('/tmp/notifications-pushbullet-class.log', "Empty access token\n", FILE_APPEND);
         return;
     }
     $first_name = $this->process_setting($id, 'first_name');
     $last_name = $this->process_setting($id, 'last_name');
     $merge_fields = array();
     if ($first_name) {
         $merge_fields['FNAME'] = $first_name;
     }
     if ($last_name) {
         $merge_fields['LNAME'] = $last_name;
     }
     $mc = new MailChimp($api_key);
     $mc->verify_ssl = false;
     $subscriberHash = md5(strtolower(trim($email)));
     $optionsArr = array('email_address' => $email, 'status' => 'pending');
     if (count($merge_fields) > 0) {
         $optionsArr['merge_fields'] = $merge_fields;
     }
     // Original working code is post.
     $added = $mc->post("lists/{$list_id}/members", $optionsArr);
     // Opt back in code, this code should create or update a subscriber... but produces and unknown error we're unable to debug:
     // $added = $mc->put("lists/{$list_id}/members/{$subscriberHash}", $optionsArr);
     if ($added) {
         //
         // file_put_contents('mailchimp-errors.log', "Error: \n" . print_r( $added, true ) . "\n", FILE_APPEND);
     } else {
         // Could be SSL-verify of cURL that fai
         file_put_contents('mailchimp-errors.log', "Error: \n" . print_r($added, true) . "\n", FILE_APPEND);
         file_put_contents('mailchimp-errors.log', $subscriberHash . "\n", FILE_APPEND);
         file_put_contents('mailchimp-errors.log', print_r($optionsArr, true) . "\n", FILE_APPEND);
     }
 }
Пример #10
0
 /**
  * Make a request to the Mailchimp API.
  *
  * @param  string $method   Request method (get, post, patch etc)
  * @param  string $endpoint Endpoint URL (e.g 'lists')
  * @param  array  $args     Request arguments
  * @return array            Response data
  *
  * @throws \Exception On error
  */
 private function request($method, $endpoint, $args = [])
 {
     $data = $this->mc->{$method}($endpoint, $args, 5);
     $response = $this->mc->getLastResponse();
     if (isset($response['headers']['http_code'])) {
         switch (substr($response['headers']['http_code'], 0, 1)) {
             case '4':
                 throw new Exception($data['title'] . ': ' . $data['detail']);
             case '5':
                 throw new Exception('Mailchimp API 500 error. Service may be unavailable.');
             default:
                 return $data;
         }
     } else {
         throw new Exception('Unknown Mailchimp error: ' . $this->mc->getLastError());
     }
 }
Пример #11
0
 /**
  * @param string $email
  *
  * @return string
  */
 protected function getSubscriberHash($email)
 {
     return $this->mailChimp->subscriberHash($email);
 }
Пример #12
0
<?php

include 'libraries/Mailchimp.php';
use DrewM\MailChimp\MailChimp;
$mailChimp = new MailChimp('27f9b677ffb5e53f3d000bfd19ca305f-us12');
$listData = $mailChimp->get('lists');
if ($listData) {
    $listId = $listData['lists'][0]['id'];
    $subscriberEmail = filter_input(INPUT_POST, 'email');
    $subscriber = $mailChimp->post("lists/{$listId}/members", ['email_address' => $subscriberEmail, 'status' => 'subscribed']);
}
Пример #13
0
{
    print_r(json_encode(array('status' => 'error', 'detail' => $message)));
}
if (!isset($_POST['newsletter_mail'])) {
    mailchimpItError('missing email parameter');
} else {
    try {
        $api_key = getenv('MAILCHIMP_API_KEY');
        // PUT YOUR MAILCHIMP API KEY HERE
        $list_id = getenv('MAILCHIMP_LIST_ID');
        // PUT YOUR MAILCHIMP LIST ID HERE
        $email = $_POST['newsletter_mail'];
        $merge_vars = array();
        if (isset($_POST['newsletter_first_name'])) {
            $merge_vars['FNAME'] = $_POST['newsletter_first_name'];
        }
        if (isset($_POST['newsletter_last_name'])) {
            $merge_vars['LNAME'] = $_POST['newsletter_last_name'];
        }
        $mailchimp = new MailChimp($api_key);
        $result = $mailchimp->post('lists/' . $list_id . '/members', array('email_address' => $email, 'status' => 'subscribed', 'merge_fields' => $merge_vars));
        if ($result) {
            print_r(json_encode($result));
        } else {
            mailchimpItError('Please check your configuration');
        }
    } catch (Exception $e) {
        error_log($e->getMessage(), 0);
        mailchimpItError('An error has occurred, please try again later.');
    }
}
 /**
  * Populates a MailChimp Campaign with Blog content via the API.
  *
  * @param MailChimp $mailChimp
  * @param Int $campaignID
  * @return Array
  */
 public function populateCampaignContent($mailChimp, $campaignID)
 {
     $mailChimp->put("campaigns/{$campaignID}/content", ['template' => ['id' => $this->record->TemplateID, 'sections' => ['chimpify' => $this->record->getCampaignContent()]]]);
     return $this->handleMailChimpResponse($mailChimp);
 }
 public function testGetLists()
 {
     $MailChimp = new MailChimp(getenv('MC_API_KEY'));
     $lists = $MailChimp->get('lists');
     $this->assertArrayHasKey('lists', $lists);
 }
Пример #16
0
<?php

// load in mailchimp library
include './MailChimp.php';
require_once dirname(__FILE__) . '../../../../wp-config.php';
// namespace defined in MailChimp.php
use DrewM\MailChimp\MailChimp;
// connect to mailchimp
$MailChimp = new MailChimp(get_option('api_key'));
// put your API key here
$list = get_option('list_id');
// put your list ID here
$email = $_GET['EMAIL'];
// Get email address from form
$id = md5(strtolower($email));
// Encrypt the email address
if (get_option('opt_in') == 1) {
    $opt_in = 'pending';
} else {
    $opt_in = 'subscribed';
}
// setup th merge fields
$mergeFields = array();
// remove empty merge fields
$mergeFields = array_filter($mergeFields);
$result = $MailChimp->put("lists/{$list}/members/{$id}", array('email_address' => $email, 'status' => $opt_in, 'update_existing' => true));
echo json_encode($result);
Пример #17
0
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Mailchimp demo</title>
    </head>
    <body>
        <h2>Mailchimp demo</h2>
        <?php 
include 'libraries/Mailchimp.php';
use DrewM\MailChimp\MailChimp;
$mailChimp = new MailChimp('your-api-key-goes-here');
print_r('Getting list...<br><br>');
//get all lists
$listData = $mailChimp->get('lists');
//if lists exist, get the id of the first list and add a subscriber to it.
if ($listData) {
    $listId = $listData['lists'][0]['id'];
    print_r('Mailchimp list id is: ' . $listId . '<br><br>');
    $subscriberEmail = '*****@*****.**';
    print_r('Adding subscriber...<br><br>');
    //add subscriber
    $subscriber = $mailChimp->post("lists/{$listId}/members", ['email_address' => $subscriberEmail, 'status' => 'subscribed']);
    if (isset($subscriber['id'])) {
        print_r('Mailchimp subscriber id is: ' . $subscriber['id'] . '<br><br>');
        print_r('Deleting subscriber...<br><br>');
        //delete the subscriber
        $subscriber_hash = $mailChimp->subscriberHash($subscriberEmail);
        $mailChimp->delete("lists/{$listId}/members/{$subscriber_hash}");
    } else {
        print_r($subscriber['detail'] . '<br><br>');
Пример #18
0
<?php

include 'MailChimp.php';
use DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('c2f307730d190444ebb001d308c5f5f2-us12');
$list_id = '54a4488ddb';
$result = $MailChimp->post("lists/{$list_id}/members", ['email_address' => $email, 'FNAME' => $name, 'status' => 'subscribed']);