error in send email using Mandrill (php)

15,669

Solution 1

the error is indicating you don't have the required SSL cert installed locally to verify the SSL connection with Mandrill's API. You can get a bundle of certs through a package manager for your operating system, or you can download the bundle that's distributed with Mozilla: http://curl.haxx.se/docs/caextract.html and then store them locally.

Solution 2

At this file: mandrill-api-php\src\Mandrill.php

At line 58 where initialize curl:

$this->ch = curl_init();

You need to add this two options to solve the problem:

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

Or you have this option to: HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK

Solution 3

After downloading cacert.pem from http://curl.haxx.se/docs/caextract.html and putting it on my server, I was able to fix this problem (while keeping everything secure) with the following:

$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');

The curl property in the Mandrill class is public, so there is no need to add hacks to the library itself.

Share:
15,669
Aakanksha
Author by

Aakanksha

Updated on July 21, 2022

Comments

  • Aakanksha
    Aakanksha almost 2 years

    I am using mandrill api for the first time. I am using following code. I have Mandrill API Key with me.

     <?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' => '[email protected]',
                'from_name' => 'Example Name',
                'to' => array(
                    array(
                        'email' => '[email protected]',
                        'name' => 'Recipient Name'
                    )
                ),
                'headers' => array('Reply-To' => '[email protected]'),
                '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' => '[email protected]',
                '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' => '[email protected]',
                        'vars' => array(
                            array(
                                'name' => 'merge2',
                                'content' => 'merge2 content'
                            )
                        )
                    )
                ),
                'tags' => array('password-resets'),
                'subaccount' => 'customer-123',
                'google_analytics_domains' => array('example.com'),
                'google_analytics_campaign' => '[email protected]',
                'metadata' => array('website' => 'www.example.com'),
                'recipient_metadata' => array(
                    array(
                        'rcpt' => '[email protected]',
                        '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;
        }
        ?>
    

    By using this code I am getting error as:

    A mandrill error occurred: Mandrill_HttpError - API call to messages/send failed: error setting certificate verify locations: CAfile: /usr/local/share/certs/ca-root-nss.crt CApath: none

    Why am I getting this error?

  • behz4d
    behz4d over 10 years
    this didn't help... .
  • Gabriel Anderson
    Gabriel Anderson about 10 years
    after download the cert, add to PHP.ini: curl.cainfo = "PATH_TO/cacert.pem"
  • Kaitlin
    Kaitlin about 10 years
    If you set those two options to 0, you're effectively turning off SSL verification, which opens you up to potential security vulnerabilities, and is definitely not recommended.
  • Nathan Waters
    Nathan Waters about 9 years
    I'm still getting the same error after downloading the pem file and adding curl.cainfo = c:\wamp\cacert.pem to php.ini
  • PC.
    PC. almost 9 years
    somehow i am also not able to get it solved even after downloading certification and configuring in correct php.ini file! but many suggests only this is right solution
  • Mladen Janjetovic
    Mladen Janjetovic almost 9 years
    I use this only in localhost, because I couldn't make it work with cert on Windows. For production this is commented
  • Tets Tets
    Tets Tets about 8 years
    This worked for me but, JFYI, CURLOPT_SSL_VERIFYHOST should be set to 2 not true, true was deprecated.