Zend框架-PHP mailchimp从来没有工作过,为什么它什么都不做


Zend framework - PHP mailchimp is never working any reason why its not doing anything at all?

为什么邮件chimp不能在具有以下功能的ZF1和ZF2中工作?

class TestController extends Zend_Controller_Action {
  public function indexAction() {
   echo  $this->Mailb(
                  "from@gmail.com", 
                  "to@gmail.com", 
                  "Mail sucks",
                  "PING PINGO",
                  'me@gmail.com,me1@gmail.com,me2@gmail.com', 
                  );
  }
  public static function Mailb($from, $to, $subject, $htmlBody, 
          $bcc = '') {
    $uri = 'https://mandrillapp.com/api/1.0/messages/send.json';
    $postString = '{
    "key": "erewrrwerewrewrewrewrewr",
    "message": {
        "html": "' .$htmlBody. '",
        "text":  "' .$htmlBody. '",
        "subject": "' .$subject.'",
        "from_email": "' .$from. '",
        "from_name": "BLA 1",
        "to": [
            {
                "email": "' . $to . '",
                "name": "BLA 2"
            }
        ],
        "headers": {
        },
        "track_opens": true,
        "track_clicks": true,
        "auto_text": true,
        "url_strip_qs": true,
        "preserve_recipients": true,
        "merge": true,
        "global_merge_vars": [
        ],
        "merge_vars": [
        ],
        "tags": [
        ],
        "google_analytics_domains": [
        ],
        "google_analytics_campaign": "...",
        "metadata": [
        ],
        "recipient_metadata": [
        ],
        "attachments": [
        ]
    },
    "async": false
    }';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $uri);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
    $result = curl_exec($ch);    
  }
}

编辑:主要错误

现在:[{"email":"to@gmail.com","status":"sent","_id":"1cbe2f9a2d","reject_reason":nul‌​l}]

只是猜测。

您只是将裸露的参数$htmlBody$subject等转储到JSON模板中。为了创建有效的JSON负载,可能需要对一些斜杠或引号进行编码。MailChimp可能检测到无效的有效负载,并向您报告错误。

我可能会创建一个PHP数组,然后使用json_encode($arr)来构建有效负载。通过这种方式,这些变量中斜杠和引号的所有编码都由json_encode本身处理。

具体而言:

$postData = array(
    'key' => 'mykey',
    'message' => array(
        'html' => $htmlBody,
        'text' => $htmlBody,
        'subject' => $htmlBody,
        'subject' => $subject,
        'from_email' => $from,
        // etc
    ),
);
$postString = json_encode($postData);
// Then post via `curl_xxx()` as before

第二个想法,可能更多的是风格而非实质:方法Mailb()是静态声明的,但使用$this->Mailb()调用。我可能会用self::Mailb()来称呼它。

相关文章: