使用Mailgun-php库使用示例代码发送Mailgun:HttpClientException

时间:2017-12-16 21:19:23

标签: php mailgun

我有一个新的,激活的,付费的mailgun帐户,所有域都已设置和验证。将他们的示例代码与我的密钥和域一起使用:

method

我收到错误输出

$mg = Mailgun::create('key-XXXXX');

$mg->messages()->send('mailgun.MYDOMAIN.com', [
    'from'    => 'bob@mailgun.MYDOMAIN.com',
    'to'      => 'sally@mailgun.MYDOMAIN.com',
    'subject' => 'The PHP SDK is awesome',
    'text'    => 'It is so simple to send a message'
]);

响应对象的Fatal error: Uncaught exception 'Mailgun\Exception\HttpClientException' with message 'The parameters passed to the API were invalid. Check your inputs!' in /home/MYDOMAIN/public_html/include/vendor/mailgun/mailgun-php/src/Mailgun/Exception/HttpClientException.php:59 Stack trace: #0 /home/MYDOMAIN/public_html/include/vendor/mailgun/mailgun-php/src/Mailgun/Api/HttpApi.php(91): Mailgun\Exception\HttpClientException::badRequest(Object(GuzzleHttp\Psr7\Response)) #1 /home/MYDOMAIN/public_html/include/vendor/mailgun/mailgun-php/src/Mailgun/Api/HttpApi.php(73): Mailgun\Api\HttpApi->handleErrors(Object(GuzzleHttp\Psr7\Response)) #2 /home/MYDOMAIN/public_html/include/vendor/mailgun/mailgun-php/src/Mailgun/Api/Message.php(52): Mailgun\Api\HttpApi->hydrateResponse(Object(GuzzleHttp\Psr7\Response), 'Mailgun\\Model\\M...') #3 /home/MYDOMAIN/public_html/test.php(40): Mailgun\Api\Message->send('mailgun.MYDOMAIN...', Array) #4 {main} thrown in /home/MYDOMAIN/public_html/include/vendor/mailgun/mailgun-php/src/Mailgun/Exception/HttpClientException.php on line 59 给了我......不多:

var_dump()

我尝试使用他们在github上发布的调试解决方案:

object(GuzzleHttp\Psr7\Response)#32 (6) {
  ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
  string(11) "BAD REQUEST"
  ["statusCode":"GuzzleHttp\Psr7\Response":private]=>
  int(400)
  ["headers":"GuzzleHttp\Psr7\Response":private]=>
  array(5) {
    ["Content-Type"]=>
    array(1) {
      [0]=>
      string(16) "application/json"
    }
    ["Date"]=>
    array(1) {
      [0]=>
      string(29) "Sat, 16 Dec 2017 21:06:26 GMT"
    }
    ["Server"]=>
    array(1) {
      [0]=>
      string(5) "nginx"
    }
    ["Content-Length"]=>
    array(1) {
      [0]=>
      string(3) "137"
    }
    ["Connection"]=>
    array(1) {
      [0]=>
      string(10) "keep-alive"
    }
  }
  ["headerNames":"GuzzleHttp\Psr7\Response":private]=>
  array(5) {
    ["content-type"]=>
    string(12) "Content-Type"
    ["date"]=>
    string(4) "Date"
    ["server"]=>
    string(6) "Server"
    ["content-length"]=>
    string(14) "Content-Length"
    ["connection"]=>
    string(10) "Connection"
  }
  ["protocol":"GuzzleHttp\Psr7\Response":private]=>
  string(3) "1.1"
  ["stream":"GuzzleHttp\Psr7\Response":private]=>
  object(GuzzleHttp\Psr7\Stream)#31 (7) {
    ["stream":"GuzzleHttp\Psr7\Stream":private]=>
    resource(83) of type (stream)
    ["size":"GuzzleHttp\Psr7\Stream":private]=>
    NULL
    ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["readable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["writable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["uri":"GuzzleHttp\Psr7\Stream":private]=>
    string(10) "php://temp"
    ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
    array(0) {
    }
  }
}

只提供了另一个无用的错误响应:

$configurator = new Mailgun\HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/f1e56c6a');
$configurator->setDebug(true);
$mg = Mailgun\Mailgun::configure($configurator);

# Now, compose and send your message.
$mg->messages()->send('example.com', [
    'from'    => 'bob@example.com',
    'to'      => 'sally@example.com',
    'subject' => 'The PHP SDK is awesome!',
    'text'    => 'It is so simple to send a message.'
]);

我正在使用PHP v5.6.32。我无法收集任何信息来解决此错误。任何人都有这方面或任何想法的经验吗?

1 个答案:

答案 0 :(得分:0)

Mailgun有一个糟糕的错误消息。支持人员已与我联系并说'The parameters passed to the API were invalid. Check your inputs!'表示虽然我已验证了我的电子邮件,验证了我的域名并验证了我的信用卡,但我还没有将手机号码与我的帐户相关联。