我在Windows 7上运行PHP Version 5.6.3作为XAMPP的一部分。

当我尝试使用Mandrill API时,我得到以下错误:

未捕获的异常“Mandrill_HttpError”与消息“API调用消息/发送模板失败:SSL证书问题:无法获得本地颁发者证书”

我已经尝试了我在StackOverflow上读到的所有内容,包括将以下内容添加到php.ini文件:

curl.cainfo = "C:\xampp\php\cacert.pem"

当然也下载到了cacert。来自http://curl.haxx.se/docs/caextract.html的Pem文件

但是在这之后,重新启动XAMPP和Apache服务器,但仍然得到相同的错误。

我真的不知道还能试什么。

有没有人能建议我还能尝试些什么?


当前回答

你可以试试这个:

$client = new Client(env('API_HOST'));
$client->setSslVerification(false);

测试在guzzle/guzzle 3.*

其他回答

编者注:禁用SSL验证存在安全隐患。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

我试过了,很管用

open

vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

改变这个

 $conf[CURLOPT_SSL_VERIFYHOST] = 2;
 $conf[CURLOPT_SSL_VERIFYPEER] = true;

这个

$conf[CURLOPT_SSL_VERIFYHOST] = 0;
$conf[CURLOPT_SSL_VERIFYPEER] = FALSE;

注意:关闭SSL验证功能存在安全影响。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

详细阐述了服务器部署的上述答案。

$hostname = gethostname();
if($hostname=="mydevpc")
{
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}

应该在部署时不影响服务器的情况下完成开发环境的技巧。

编者注:禁用SSL验证存在安全隐患。如果不验证SSL/HTTPS连接的真实性,恶意攻击者可以模拟可信端点(如GitHub或其他远程Git主机),您将容易受到中间人攻击。 在使用此解决方案之前,请确保您完全理解安全问题。

我在mandrilli .php文件第65行后也有同样的问题,它说$this->ch = curl_init();

增加以下两行:

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

这解决了我的问题,并使用localhost发送电子邮件,但我建议不要在live版本上使用它。在您的活动服务器上,代码应该可以在没有此代码的情况下工作。

当你浏览http://curl.haxx.se/docs/caextract.html页面时,你会注意到一个用大字母写的部分:

RSA-1024把

阅读本文,然后下载包含“RSA-1024”证书的证书版本。 https://github.com/bagder/ca-bundle/blob/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt

这些将与Mandrill一起工作。

禁用SSL是一个坏主意。

终于让这个工作了!

Download the certificate bundle. Put it somewhere. In my case, that was c:\wamp\ directory (if you are using Wamp 64 bit then it's c:\wamp64\). Enable mod_ssl in Apache and php_openssl.dll in php.ini (uncomment them by removing ; at the beginning). But be careful, my problem was that I had two php.ini files and I need to do this in both of them. One is the one you get from your WAMP taskbar icon, and another one is, in my case, in C:\wamp\bin\php\php5.5.12\ Add these lines to your cert in both php.ini files: curl.cainfo="C:/wamp/cacert.pem" openssl.cafile="C:/wamp/cacert.pem" Restart Wamp services.