【问题标题】:Mandrill giving invalid app key errorMandrill 给出无效的应用程序密钥错误
【发布时间】:2012-05-05 09:23:35
【问题描述】:

我只是想将 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 密钥,但我仍然遇到同样的错误。

【问题讨论】:

    标签: php codeigniter email mailchimp


    【解决方案1】:

    如果您使用的是 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】:

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

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

      【讨论】:

        【解决方案3】:

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

        顺便说一句,您应该先尝试拨打用户/ping 电话。

        【讨论】:

        • 先调用 users/ping 有什么作用?
        • @Williams Castillo - 像 916 Networks,先检查 users/ping 呼叫的目的是什么?
        猜你喜欢
        • 2014-08-05
        • 2019-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-31
        • 2015-10-04
        • 1970-01-01
        相关资源
        最近更新 更多