Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对于PHP SDK,Mailgun抛出致命错误而不是异常_Php_Mailgun - Fatal编程技术网

对于PHP SDK,Mailgun抛出致命错误而不是异常

对于PHP SDK,Mailgun抛出致命错误而不是异常,php,mailgun,Php,Mailgun,我正在尝试实现Mailgun API系列来处理我的电子邮件,根据文档,这是我的代码: index.php require 'vendor/autoload.php'; use Mailgun\Mailgun; $mgClient = Mailgun::create("key-xxxxxxxxxxxxxxxxxxxxxxxxxxx"); $domain = "xxxxxxx.com"; $mgClient->sendMessage($domain,

我正在尝试实现Mailgun API系列来处理我的电子邮件,根据文档,这是我的代码:

index.php

require 'vendor/autoload.php';
use Mailgun\Mailgun;

$mgClient = Mailgun::create("key-xxxxxxxxxxxxxxxxxxxxxxxxxxx"); 
$domain = "xxxxxxx.com"; 


$mgClient->sendMessage($domain, 
                       array('from' => 'Dwight Schrute<dwight@xxxxxxx.com>', 
                             'to' => 'Michael Scott <xxxx@xxxxx.com>', 
                             'subject' => 'The Printer Caught Fire', 
                             'text' => 'We have a problem.'));

var_dump($result);
一切正常,但$result包含大量数据,而不是id为且消息为“message was queued thanky you”的简单返回数组。另一个问题是,当我模拟错误以查看发生的情况时,不幸的是,Mailgun产生了致命错误,而不是我可以处理的连接异常:

[30-Nov-2017 10:05:44 UTC] PHP Fatal error:  Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs! Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.' in /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:254
Stack trace:
#0 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(110): Mailgun\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response))
#1 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(179): Mailgun\Connection\RestClient->send('POST', 'xxxxx.com...', Array, Array)
#2 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(204): Mailgun\Connection\RestClient->post('xxxxx.com...', Array, Array)
#3 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(135): Mailgun\Mailgun->post(' in /home/xxxxxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 254

我使用的是PHP7操作系统linux无框架。我做错了什么?感谢您的建议。

每当使用沙盒域或免费帐户而不邀请称为授权收件人的用户时,就会发生此错误。免费计划用于测试使用,所有自定义域都需要授权收件人。使用升级的计划,自定义域不再需要授权收件人

有关授权收件人流程的更多信息,请参阅以下帮助中心文章:

有关升级的详细信息,请查看:


免责声明我在邮枪工作

你是什么意思?它正在抛出一个异常,因为它在错误消息中非常清楚地说明了这一点。您没有捕获它,因此它会导致一个致命错误。@boosterV Itt感谢您的回答,是的,我知道,正如我所说,我犯这个错误是为了看看脚本的行为。对于异常,我将使用try-catch块。在使用PHPSDK发送消息时,我会得到大量数据,而不是id为的简单返回数组和消息“MessagewasQueuedThankyou”,这是否正常?
[30-Nov-2017 10:05:44 UTC] PHP Fatal error:  Uncaught exception 'Mailgun\Connection\Exceptions\MissingRequiredParameters' with message 'The parameters passed to the API were invalid. Check your inputs! Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.' in /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:254
Stack trace:
#0 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(110): Mailgun\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response))
#1 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(179): Mailgun\Connection\RestClient->send('POST', 'xxxxx.com...', Array, Array)
#2 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(204): Mailgun\Connection\RestClient->post('xxxxx.com...', Array, Array)
#3 /home/xxx/xxx/vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(135): Mailgun\Mailgun->post(' in /home/xxxxxx/vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php on line 254