我使用mailgun-php调用mailgun,通过GoDaddy窗口托管上的php页面发送消息。我刚刚按照安装说明重新安装了最新的mailgun php。现在我收到这个错误消息。我在GoDaddy windows主机上可以拥有的PHP最高版本是5.6。我找了好几个小时都没找到答案。错误消息下面是我的代码。
〔2018年12月15日10:36:22美国/凤凰城〕PHP致命错误:未捕获异常"Http\Client\exception\RequestException",消息为"error"设置证书验证位置:CA文件:c: \cgi\php56\cur-ca-bundle.crt CApath:none'D: \Hosting\redated\mailgun php\vendor\phphttp\ccurl client\src\client.php:137堆栈跟踪:
0 D:\Hosting\redated\mailgun php\vendor\mailgun\mailgun php\src\mailgun\Connection\RestClient.php(108(:
Http\Client\Coll\Client->sendRequest(对象(GuzzleHttp\Psr7\Request((
1 D:\Hosting\redated\mailgun php\vendor\mailgun\mailgun php\src\mailgun\Connection\RestClient.php(179(:
Mailgun\Connection\RestClient->发送("POST","…",阵列,阵列(
2 D:\Hosting\redated\mailgun php\vendor\mailgun\mailgun php\src\mailgun\mailgun.php(204(:
Mailgun\Connection\RestClient->post('..',Array,Array(
3 D:\Hosting\redated\mailgun php\sendmail.php(66(:D:\Hosting \redated\mailgun php\vendor \phphttp\ccurl client\src\client.php中的邮件
在线137
<?php
error_reporting(E_ALL);
ini_set ('log_errors', 'on');
ini_set ('display_startup_errors', 'on');
ini_set ('error_reporting', E_ALL);
ini_set('error_log','D:Hostingredactedhtmlphplogsphp_errors.log');
require 'vendor/autoload.php';
use MailgunMailgun;
if(strtoupper($_SERVER['REQUEST_METHOD']) != 'POST')
die('Invalid Mail Send request - rejected');
$message = htmlspecialchars($_POST['message']);
$subject = htmlspecialchars($_POST['subject']);
$attachments = json_decode($_POST['attachments']);
$toName = htmlspecialchars($_POST['toName']);
$toAddress = htmlspecialchars($_POST['toAddress']);
$emailTag = htmlspecialchars($_POST['email_tag']);
$from = "Site.com <quote@site.com>";
$domain = "<domain>";
error_log('>>>>>> ' . $emailTag);
// setup credentials
$mg = new Mailgun("key");
# Next, instantiate a Message Builder object from the SDK.
$msgBldr = $mg->MessageBuilder();
# Define the from address.
$msgBldr->setFromAddress($from);
# Define a to recipient.
$msgBldr->addToRecipient($toAddress);
#Define bcc for maintenance
$msgBldr->addBccRecipient('dev@dev.com');
# Define the subject.
$msgBldr->setSubject($subject);
# Define the body of the message.
$msgBldr->setTextBody($message);
$tempfiles = array();
# Add attachments
error_log("Attachment Count: " . strval(count($attachments)));
foreach ($attachments as $key => $value){
$temp_file = tempnam(sys_get_temp_dir(), $value->name);
file_put_contents($temp_file, base64_decode($value->content));
$attSuccess = $msgBldr->addAttachment($temp_file, $value->name);
$tempfiles[] = $temp_file;
}
$msg = $msgBldr->getMessage();
error_log("Message to send: " . json_encode($msg));
$files = $msgBldr->getFiles();
error_log("Sending files: " . json_encode($files));
$postAddr = "$domain/messages";
error_log("PostTo: " . $postAddr);
# Finally, send the message.
$mg->post($postAddr, $msg, $files);
// clean up temp files
foreach($tempfiles as $key => $f_name){
unlink($f_name);
}
?>
在Windows下,当您没有定义有效的新CA文件时,有时会遇到curl问题。
https://superuser.com/questions/442793/why-cant-curl-properly-verify-a-certificate-on-windows
下面是一个如何下载和定义ca文件的示例。我不知道这是否能解决你的问题,但你可以尝试一下。也许这样你就能获得有效的连接。