Mandrill提供无效的应用密钥错误

时间:2012-04-24 17:33:19

标签: php codeigniter email-integration mailchimp

我只想尝试将mandrill邮件发送到我的应用程序下面是我在php中的代码

$args = array(
    'key' => '73357ad2-e59e-4669---------',
    'message' => array(
        "html" => "<p>\r\n\tHi Adam,</p>\r\n<p>\r\n\tThanks for <a href=\"http://mandrill.com\">registering</a>.</p>\r\n<p>etc etc</p>",
        "text" => null,
        "from_email" => "xxx@xxx.com",
        "from_name" => "SIVOnline",
        "subject" => "Your recent registration",
        "to" => array(array("email" => "xxx@xxx.com")),
        "track_opens" => true,
        "track_clicks" => true,
        "auto_text" => true
    )   
);
// Open a curl session for making the call

$curl = curl_init('https://mandrillapp.com/api/1.0/messages/send.json' );
// Tell curl to use HTTP POST
curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// Tell curl not to return headers, but do return the response
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Set the POST arguments to pass on
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($args));

// Make the REST call, returning the result
$response = curl_exec($curl);


 // Close the connection
    curl_close( $curl ); 

并且在重新生成密钥后它给了我无效的api密钥仍然会出现同样的错误。

3 个答案:

答案 0 :(得分:2)

在将$args变量传递给CURLOPT_POSTFIELDS setopt调用时,不要对其进行JSON编码。

顺便说一句,你应该先尝试进行用户/ ping通话。

答案 1 :(得分:2)

如果您使用的是Mandrill官方API,请点击此处https://packagist.org/packages/mandrill/mandrill

你会这样做

require_once(Mandrill.php);

$apikey = "YOUR-API-KEY";

$Mandrill = new Mandrill($apikey);


$params = array(
        "html" => "<p>\r\n\tHi Adam,</p>\r\n<p>\r\n\tThanks for <a href=\"http://mandrill.com\">registering</a>.</p>\r\n<p>etc etc</p>",
        "text" => null,
        "from_email" => "xxx@xxx.com",
        "from_name" => "chris french",
        "subject" => "Your recent registration",
        "to" => array(array("email" => "xxx@xxxx.com")),
        "track_opens" => true,
        "track_clicks" => true,
        "auto_text" => true
);

$Mandrill->messages->send($params, true);

答案 2 :(得分:1)

提示:您可以获得PHP的全功能Mandrill API包装类

...它包含在WordPress插件包中:wpMandrill