<?php

/**
This Example shows how to schedule a campaign for future delivery
via the MCAPI class.
**/
require_once '../mcapi.php';
require_once 'config/config.inc.php';
//contains apikey
$api = new MCAPI($apikey);
$schedule_for = '2018-04-01 09:05:21';
$retval = $api->campaignSchedule($campaignId, $schedule_for);
if ($api->errorCode) {
    echo "Unable to Schedule Campaign!";
    echo "\n\tCode=" . $api->errorCode;
    echo "\n\tMsg=" . $api->errorMessage . "\n";
} else {
    echo "Campaign Scheduled to be delivered {$schedule_for}!\n";
}
Ejemplo n.º 2
0
 public function send_campaign()
 {
     $expected = array('db', 'lang', 'send_time', 'num_subscribers', 'action');
     if (!$_POST) {
         exit;
     }
     $this->campaign = array();
     foreach ($_POST as $post => $value) {
         if (in_array($post, $expected)) {
             $this->campaign[$post] = $value;
         }
     }
     $host = $this->host;
     $lang = $this->campaign['lang'];
     $db = $this->campaign['db'];
     $action = $this->campaign['action'];
     $send_time = $this->campaign['send_time'];
     $api_key = $this->get_setting('api_key');
     $html = $this->get_file("{$host}?lang={$lang}&production");
     $html = $this->filter_html_campaign_code($html);
     $campaign_type = $this->get_setting('type');
     $formatted_db_name = str_replace('_', ' ', strtoupper($db));
     //add into the $opts this EDMs specifics:
     $opts = $this->get_setting('options');
     $opts['list_id'] = $this->get_setting('prod_list');
     $opts['title'] .= ' ' . $formatted_db_name;
     $opts['subject'] = $this->extract_html_subject($html);
     //add tracking code
     $year = date('Y');
     $db_key = strtoupper($db);
     $opts['analytics'] = array('google' => $this->get_setting('campaign_name') . '_' . $year . '_' . $db_key);
     $opts['authenticate'] = true;
     $segment_opts = array('match' => 'all', 'conditions' => $this->get_mailchimp_sending_criteria($db));
     $api = new MCAPI($api_key);
     $campaign_id = $api->campaignCreate($campaign_type, $opts, array('html' => $html), $segment_opts);
     if ($action === 'schedule') {
         $local = $this->get_send_time_and_offset(false, false, $send_time);
         $tmp = strtotime($send_time) - $local['total_offset'];
         $send_time = date('Y-m-d H:i:s', $tmp);
         $campaign_id = $api->campaignSchedule($campaign_id, $send_time);
     }
     if ($api->errorCode) {
         $this->send_json(array('fail' => $api->errorMessage));
     } else {
         $this->set_cache($campaign_id);
         $this->send_json(array('success' => $campaign_id));
     }
     exit;
 }