2012-04-24 5 views
3
私はちょうど下の私のアプリで送信マンドリルメールを統合しようとしています

は、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" => "[email protected]", 
     "from_name" => "SIVOnline", 
     "subject" => "Your recent registration", 
     "to" => array(array("email" => "[email protected]")), 
     "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); 

あり、それはまだキーをregenarating私は取得しています後に私に無効なAPIキーを与えています同じエラー。

答えて

2

$args変数をCURLOPT_POSTFIELDSのsetopt呼び出しに渡すときにJSONエンコードしないでください。

ところで、まずはユーザー/ pingコールを行うようにしてください。

+0

のようにそれを行うだろうか? –

+0

@Williams Castillo - 916 Networksのように、まずユーザー/ pingコールをチェックする目的は何ですか? – JM4

1

ヒント:あなたがここにありますマンドリル公式APIを使用している場合wpMandrill

2

:あなたはそれはWordPressのプラグインのパッケージに含まれています... PHP

のための完全な機能をマンドリルのAPIのラッパークラスを取得することができますhttps://packagist.org/packages/mandrill/mandrill

あなたはユーザー/ pingのコールが最初にやらせん何この

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" => "[email protected]", 
     "from_name" => "chris french", 
     "subject" => "Your recent registration", 
     "to" => array(array("email" => "[email protected]")), 
     "track_opens" => true, 
     "track_clicks" => true, 
     "auto_text" => true 
); 

$Mandrill->messages->send($params, true); 
関連する問題