Drupal 7 Drupal 7以编程方式创建和发送mailchimp活动

Drupal 7 Drupal 7以编程方式创建和发送mailchimp活动,drupal-7,mailchimp,Drupal 7,Mailchimp,如何在drupal 7中以编程方式创建和发送mailchimp活动?函数kf\u mailchimp\u create\u campaign(){ function kf_mailchimp_create_campaign() { if (!isset($_GET['cron_key']) || ($_GET['cron_key'] != 'kQ7kOy4uRgPJd1FX1QQAERPeSYuPjp1qBW65goYcbDQ')) { watchdog('kf_mailchimp'

如何在drupal 7中以编程方式创建和发送mailchimp活动?

函数kf\u mailchimp\u create\u campaign(){
function kf_mailchimp_create_campaign() {
  if (!isset($_GET['cron_key']) || ($_GET['cron_key'] != 'kQ7kOy4uRgPJd1FX1QQAERPeSYuPjp1qBW65goYcbDQ')) {
    watchdog('kf_mailchimp', 'Invalid cron key !cron_key has been used to create campaign.', array('!cron_key' => $_GET['cron_key']));
    drupal_exit();
  }

  $data['site_url'] = url('<front>', array('absolute' => TRUE));
  $data['site_logo'] = theme_image(array(
    'path' => drupal_get_path('theme', 'knackforge') . '/logo.png',
    'alt' => 'KnackForge',
    'attributes' => array('border' => 0),
  ));

  $options = array(
    'list_id' =>  $mc_list_id, // Change this to match list id from mailchimp.com.
    'from_email' => variable_get('site_mail'),
    'from_name' => 'KnackForge',
    'to_email' => variable_get('site_name')
  );

  $type = 'regular';
  $q = mailchimp_get_api_object(); // Make sure a list has been created in your drupal site.

  $results = views_get_view_result('deal_mailchimp', 'page');
  // Check to prevent sending empty newsletter
  if (empty($results)) {
    watchdog('kf_mailchimp', 'No active deals to send for today');
    drupal_exit();
  }

  $data['deals'] = views_embed_view('deal_mailchimp', 'page');

  $content = array(
    'html' => theme('kf_mailchimp', $data),
  );

  $options['subject'] = t('Newsletter');
  $options['title'] = $options['subject'] . ' - ' . date('r');
  $options['tracking'] = array(
    'opens' => TRUE,
    'html_clicks' => TRUE,
    'text_clicks' => TRUE
  );

  $options['authenticate'] = false;
  $options['analytics'] = array('google'=>'atphga');

  $cid = $q->campaignCreate($type, $options, $content);

  watchdog('kf_mailchimp', 'Created campaign');

  $result = $q->campaignSendNow($cid);

  watchdog('kf_mailchimp', 'campaignSendNow() response !result', array('!result' => '<pre>' . print_r($result, 1) . '</pre>'));
如果(!isset($_-GET['cron-u-key'])| |($_-GET['cron-u-key']!='kq7koy4urgpjd1fx1qqaerpsesyupjp1qbw65goycbdq')){ watchdog('kf_mailchimp','cron key无效!cron_key已用于创建活动','array('!cron_key'=>$获取['cron_key']); drupal_exit(); } $data['site_url']=url('',数组('absolute'=>TRUE)); $data['site_logo']=主题图像(数组)( 'path'=>drupal\u get\u path('theme','knackforge')。/logo.png', “alt”=>“KnackForge”, 'attributes'=>array('border'=>0), )); $options=array( 'list\u id'=>$mc\u list\u id,//将其更改为匹配mailchimp.com中的列表id。 'from_email'=>variable_get('site_mail'), “from_name”=>“KnackForge”, 'to_email'=>variable_get('site_name')) ); $type='regular'; $q=mailchimp_get_api_object();//确保已在drupal站点中创建列表。 $results=views\u get\u view\u result('deal\u mailchimp','page'); //检查以防止发送空新闻稿 if(空($results)){ 看门狗(“kf_mailchimp”,“今天没有要发送的活动交易”); drupal_exit(); } $data['deals']=视图\嵌入\视图('deal\ mailchimp','page'); $content=array( 'html'=>主题('kf_mailchimp',$data), ); $options['subject']=t(“时事通讯”); $options['title']=$options['subject'].-'.date('r'); $options['tracking']=数组( “打开”=>TRUE, 'html_clicks'=>TRUE, “文本单击”=>TRUE ); $options['authenticate']=false; $options['analytics']=array('google'=>'atphga'); $cid=$q->ActivityCreate($type、$options、$content); 看门狗(“kf_mailchimp”,“创建活动”); $result=$q->campaignSendNow($cid); watchdog('kf_mailchimp','ActivationSendNow()响应!结果',数组('!result'=>''。print_r($result,1)。'');
这里的一些注释和解释非常适合提供上下文。