post() public method

Make an HTTP POST request - for creating and updating items
public post ( string $method, array $args = [], integer $timeout = 10 ) : array | false
$method string URL of the API request method
$args array Assoc array of arguments (usually your data)
$timeout integer Timeout limit for request in seconds
return array | false Assoc array of API response, decoded from JSON
<?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');
Exemplo n.º 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...
     }
 }
Exemplo n.º 4
0
 /**
  * @param string $fromName
  * @param string $replyTo
  * @param string $subject
  * @param string $html
  * @param string $listName
  * @param array  $options
  * @param array  $contentOptions
  *
  * @return array|bool
  *
  * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
  */
 public function createCampaign($fromName, $replyTo, $subject, $html = '', $listName = '', $options = [], $contentOptions = [])
 {
     $list = $this->lists->findByName($listName);
     $defaultOptions = ['type' => 'regular', 'recipients' => ['list_id' => $list->getId()], 'settings' => ['subject_line' => $subject, 'from_name' => $fromName, 'reply_to' => $replyTo]];
     $options = array_merge($defaultOptions, $options);
     $response = $this->mailChimp->post('campaigns', $options);
     if (!$this->lastActionSucceeded()) {
         return false;
     }
     if ($html === '') {
         return $response;
     }
     if (!$this->updateContent($response['id'], $html, $contentOptions)) {
         return false;
     }
     return $response;
 }
 /**
  * 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);
     }
 }
Exemplo n.º 6
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']);
}
 /**
  * Creates a MailChimp campaign via the API.
  *
  * @param MailChimp $mailChimp
  * @return Array
  */
 public function createCampaign($mailChimp)
 {
     $mailChimp->post('campaigns', ['type' => 'regular', 'settings' => ['subject_line' => $this->record->Title, 'from_name' => $this->record->FromName, 'reply_to' => $this->record->ReplyTo]]);
     return $this->handleMailChimpResponse($mailChimp);
 }
Exemplo n.º 8
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']);
Exemplo n.º 9
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.');
    }
}