9

初めてマンドリルAPIを使用しています。次のコードを使用しています。Mandrill API キーを持っています。

 <?php
    try {
        $mandrill = new Mandrill('YOUR_API_KEY');
        $message = array(
            'html' => '<p>Example HTML content</p>',
            'text' => 'Example text content',
            'subject' => 'example subject',
            'from_email' => 'message.from_email@example.com',
            'from_name' => 'Example Name',
            'to' => array(
                array(
                    'email' => 'recipient.email@example.com',
                    'name' => 'Recipient Name'
                )
            ),
            'headers' => array('Reply-To' => 'message.reply@example.com'),
            'important' => false,
            'track_opens' => null,
            'track_clicks' => null,
            'auto_text' => null,
            'auto_html' => null,
            'inline_css' => null,
            'url_strip_qs' => null,
            'preserve_recipients' => null,
            'view_content_link' => null,
            'bcc_address' => 'message.bcc_address@example.com',
            'tracking_domain' => null,
            'signing_domain' => null,
            'return_path_domain' => null,
            'merge' => true,
            'global_merge_vars' => array(
                array(
                    'name' => 'merge1',
                    'content' => 'merge1 content'
                )
            ),
            'merge_vars' => array(
                array(
                    'rcpt' => 'recipient.email@example.com',
                    'vars' => array(
                        array(
                            'name' => 'merge2',
                            'content' => 'merge2 content'
                        )
                    )
                )
            ),
            'tags' => array('password-resets'),
            'subaccount' => 'customer-123',
            'google_analytics_domains' => array('example.com'),
            'google_analytics_campaign' => 'message.from_email@example.com',
            'metadata' => array('website' => 'www.example.com'),
            'recipient_metadata' => array(
                array(
                    'rcpt' => 'recipient.email@example.com',
                    'values' => array('user_id' => 123456)
                )
            ),
            'attachments' => array(
                array(
                    'type' => 'text/plain',
                    'name' => 'myfile.txt',
                    'content' => 'ZXhhbXBsZSBmaWxl'
                )
            ),
            'images' => array(
                array(
                    'type' => 'image/png',
                    'name' => 'IMAGECID',
                    'content' => 'ZXhhbXBsZSBmaWxl'
                )
            )
        );
        $async = false;
        $ip_pool = 'Main Pool';
        $send_at = 'example send_at';
        $result = $mandrill->messages->send($message, $async, $ip_pool, $send_at);
        print_r($result);

    } catch(Mandrill_Error $e) {
        echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();

        throw $e;
    }
    ?>

このコードを使用すると、次のようなエラーが発生します。

mandrill エラーが発生しました: Mandrill_HttpError - メッセージへの API 呼び出し/送信に失敗しました: 証明書検証場所の設定エラー: CAfile: /usr/local/share/certs/ca-root-nss.crt CApath: なし

このエラーが発生するのはなぜですか?

4

3 に答える 3

27

このファイル: mandrill-api-php\src\Mandrill.php

curl を初期化する 58 行目:

$this->ch = curl_init();

この問題を解決するには、次の 2 つのオプションを追加する必要があります。

curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);

または、次のオプションがあります: HTTPS および SSL3_GET_SERVER_CERTIFICATE:証明書の検証に失敗しました。CA は OK です。

于 2013-11-22T08:47:30.117 に答える
7

このエラーは、Mandrill の API との SSL 接続を検証するために必要な SSL 証明書がローカルにインストールされていないことを示しています。お使いのオペレーティング システムのパッケージ マネージャーを介して証明書のバンドルを取得するか、Mozilla で配布されているバンドル ( http://curl.haxx.se/docs/caextract.html ) をダウンロードして、ローカルに保存することができます。

于 2013-10-07T11:30:30.333 に答える
5

http://curl.haxx.se/docs/caextract.htmlから cacert.pem をダウンロードしてサーバーに配置した後、次の方法で (すべてを安全に保ちながら) この問題を修正できました。

$mandrill = new Mandrill(MANDRILL_API_KEY);

// Fix CA issue
curl_setopt($mandrill->ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($mandrill->ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($mandrill->ch, CURLOPT_CAINFO, 'PATH_TO/cacert.pem');

Mandrill クラスの curl プロパティは public であるため、ライブラリ自体にハックを追加する必要はありません。

于 2016-01-07T16:10:38.280 に答える