Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandrill PHP unable to get local issuer SSL certificate

Tags:

php

mandrill

I've installed the Mandrill PHP API on my Windows Apache server. When trying to send an email using the code below I get the error:

Mandrill_HttpError - API call to messages/send-template failed: SSL certificate problem: unable to get local issuer certificate

It's not clear to me how Mandrill connects to my local issuer certificate. My web server does have a valid certificate and can display HTTPS pages successfully.

Any ideas?

        $mandrill = new Mandrill('MyMandrillAPIKey');

        $message = array(
            'subject' => 'Test message',
            'from_email' => 'MyEmailAddress',
            'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
            'to' => array(array('email' => 'MyEmailAddress', 'name' => 'David Splat')),
            'merge_vars' => array(array(
                'rcpt' => 'MyEmailAddress',
                'vars' =>
                array(
                    array(
                        'name' => 'FIRSTNAME',
                        'content' => $fName),
                    array(
                        'name' => 'LASTNAME',
                        'content' => $lName)
            ))));

        $template_name = 'MyTemplateName';

        $template_content = array(
            array(
                'name' => 'main',
                'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, thanks for signing up.'),
            array(
                'name' => 'footer',
                'content' => 'Copyright 2014.')

        );

        print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));

    } catch(Mandrill_Error $e) {
        // Mandrill errors are thrown as exceptions
        echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
        throw $e;
    }
like image 455
Dave Splat Avatar asked Nov 09 '14 12:11

Dave Splat


People also ask

How do I fix unable to get local issuer certificate?

When ssl certificate problem unable to get local issuer certificate error is caused by a self-signed certificate, the fix is to add the certificate to the trusted certificate store. Open the file ca-bundle. crt located in the directory above, then copy and paste the Git SSL certificate to the end of the file.


2 Answers

You don't need to turn off curl SSL option, instead you can download the cacert.pem file from http://curl.haxx.se/docs/caextract.html and then include it in either php.ini file curl.cainfo="/exact/location/to/cacert.pem"

or simply change the lines in Mandrill.php file to use it as below.

curl_setopt ($this->ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt ($this->ch, CURLOPT_CAINFO, __DIR__ . "/cacert.pem")

link to the post http://tutewall.com/ssl-certificate-problem-unable-to-get-local-issuer-certificate/

like image 104
Tekz Avatar answered Oct 16 '22 13:10

Tekz


Here is a change that fixed my problem. In Mandrill.php add these two lines after the call to curl_init():

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

This approach was suggested by one of the answers at error in send email using Mandrill (php)

like image 29
Dave Splat Avatar answered Oct 16 '22 13:10

Dave Splat