5

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

4

3 回答 3

2

如果您使用的是位于此处https://packagist.org/packages/mandrill/mandrill的 Mandrill 官方 API ?

你会这样做

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);
于 2013-01-20T01:53:40.747 回答
2

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

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

于 2012-04-26T20:10:08.517 回答
1

提示:你可以获得一个用于 PHP 的功能齐全的 Mandrill API 包装类

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

于 2012-05-12T13:52:21.817 回答