我正在使用mailgun-php调用mailgun,以通过GoDaddy Windows托管上的PHP页面发送消息。我按照安装说明重新开始安装了最新的mailgun-php。现在,我收到此错误消息。我可以在GoDaddy Windows托管上使用的PHP的最高版本是5.6。我已经搜索了几个小时,却找不到答案。错误消息下方是我的代码。
[2018年12月15日10:36:22美国/凤凰城] PHP致命错误:未捕获 带有消息“错误”的异常“ Http \ Client \ Exception \ RequestException” 设置证书验证位置:CAfile: c:\ cgi \ php56 \ curl-ca-bundle.crt CApath:无 D:\ Hosting \ redacted \ mailgun-php \ vendor \ php-http \ curl-client \ src \ Client.php:137 堆栈跟踪:
0 D:\ Hosting \ rededed \ mailgun-php \ vendor \ mailgun \ mailgun-php \ src \ Mailgun \ Connection \ RestClient.php(108):
Http \ Client \ Curl \ Client-> sendRequest(Object(GuzzleHttp \ Psr7 \ Request))
1 D:\ Hosting \ rededed \ mailgun-php \ vendor \ mailgun \ mailgun-php \ src \ Mailgun \ Connection \ RestClient.php(179):
Mailgun \ Connection \ RestClient-> send('POST','...',Array,Array)
2 D:\ Hosting \ rededed \ mailgun-php \ vendor \ mailgun \ mailgun-php \ src \ Mailgun \ Mailgun.php(204):
Mailgun \ Connection \ RestClient-> post('..',Array,Array)
3 D:\ Hosting \ redacted \ mailgun-php \ sendmail.php(66):D:\ Hosting \ redacted \ mailgun-php \ vendor \ php-http \ curl-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:\Hosting\redacted\html\phplogs\php_errors.log');
require 'vendor/autoload.php';
use Mailgun\Mailgun;
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);
}
?>
答案 0 :(得分:0)
在Windows下,当您没有定义有效的新CA文件时,有时会遇到卷曲问题。
https://superuser.com/questions/442793/why-cant-curl-properly-verify-a-certificate-on-windows
这里是一个如何下载和定义ca文件的示例。我不知道这是否可以解决您的问题,但您可以尝试一下。也许然后您获得有效的连接。