Monday, September 2, 2013

MailChimp API V2.0 SSL error solution

I got this SSL error while trying to use MailChimp API V2.0 in my localhost.

Fatal error: Uncaught exception 'Mailchimp_HttpError' with message 'API call to lists/list failed: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' in C:\Installation\xampp\htdocs\mailchimp-test\Mailchimp.php:192 Stack trace: #0 C:\Installation\xampp\htdocs\mailchimp-test\mailchimp-api.php(16): Mailchimp->call('lists/list', Array) #1 {main} thrown in C:\Installation\xampp\htdocs\mailchimp-test\Mailchimp.php on line 192 

To resolve this, you can try any of the methods below.

Method 1:
  • Download cacert.pem file from here: http://curl.haxx.se/docs/caextract.html
  • Save the file in your PHP installation folder. I am using xampp. So I saved it in C:\Installation\xampp\php\cacert.pem
  • Open your php.ini file and add this line:
    curl.cainfo="C:\Installation\xampp\php\cacert.pem"
  • Restart your Apache server and that should fix it.
Method 2:
If you are unable to edit php.ini file, there is a quick workaround.
  • Open the MailChimp API file (it's most likely named Mailchimp.php or MailChimp.class.php).
  • Look for statements starting with "curl_setopt".
  • Right below the set of "curl_setopt" statements, add this line:
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Both methods should work but method 1 is probably more reliable.