我尝试测试Mailgun API沙箱,以测试发送给自己的电子邮件。我下载了他们在命令行编辑器中建议使用mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7
的软件包,但是当我尝试运行PHP文件时,这是我得到的错误:
Stack trace:
#0 C:\Users\ngeoy\Desktop\emailTest.php(5): Mailgun\Mailgun->__construct('f3701c5a4bb9615...')
#1 {main}
thrown in C:\Users\ngeoy\Desktop\vendor\mailgun\mailgun-php\src\Mailgun.php on line 55
Fatal error: Uncaught TypeError: Argument 1 passed to Mailgun\Mailgun::__construct() must be an instance of Mailgun\HttpClient\HttpClientConfigurator, string given, called in C:\Users\ngeoy\Desktop\emailTest.php on line 5 and defined in C:\Users\ngeoy\Desktop\vendor\mailgun\mailgun-php\src\Mailgun.php:55
Stack trace:
#0 C:\Users\ngeoy\Desktop\emailTest.php(5): Mailgun\Mailgun->__construct('f3701c5a4bb9615...')
#1 {main}
thrown in C:\Users\ngeoy\Desktop\vendor\mailgun\mailgun-php\src\Mailgun.php on line 55
有人知道我需要更改什么或如何解析我的代码吗?
供参考,这是我的代码如下:
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('f3701c5a4b************-a2b*****-aea*****');
$domain = "sandbox0dded5a4b2bd473da5fa99ba********.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'Excited User <[email protected]>',
'to' => 'Baz <[email protected]>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!'
));
?>
(星号显然是要隐藏私人信息)
根据GitHub中的文档,您必须按以下方式使用它:
require 'vendor/autoload.php';
use Mailgun\Mailgun;
// First, instantiate the SDK with your API credentials
$mgClient = Mailgun::create('f3701c5a4b************-a2b*****-aea*****');
$domain = "sandbox0dded5a4b2bd473da5fa99ba********.mailgun.org";
// Now, compose and send your message.
$result = $mgClient->sendMessage($domain, array(
'from' => 'Excited User <[email protected]>',
'to' => 'Baz <[email protected]>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!'
));