0

为什么邮件黑猩猩不能在 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}]

4

1 回答 1

1

只是一个猜测。

您只是将裸参数 - 、 等 - 转储$htmlBody$subjectJSON 模板中。为了创建有效的 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()是静态声明的,但被称为 using $this->Mailb()。我可能会用self::Mailb().

于 2013-07-20T20:30:46.053 回答