我正试图在我的php项目中使用Mailgun。我已经安装了所有必要的组件:
这是我用来测试电子邮件服务的PHP代码:
require 'vendor/autoload.php';
ini_set('display_errors', 'On');
$client = new \Http\Adapter\Guzzle6\Client();
define('MAILGUN_KEY', 'key-xxxxxxxxxx');
define('MAILGUN_DOMAIN', 'my-domain.nl');
$mailgun = new \Mailgun\Mailgun(MAILGUN_KEY, $client);
$mailgun->sendMessage(MAILGUN_DOMAIN, [
'from' => 'my@email.com',
'to' => 'your@e-mail.com',
'subject' => 'This is a test e-mail',
'html' => "
Hello,</br></br>
This is a test."
]);它仍然引发以下错误:
Fatal error: Class 'Http\Adapter\Guzzle6\Client' not found为什么在安装和需要Guzzle6时仍然找不到composer.json?
编辑:
也许是一些重要的信息,我已经在/usr/local/lib中安装了composer和Guzzle,并使它可以在全球范围内使用。我是这样做的,还是安装在我的域名的根文件夹?
发布于 2016-09-16 10:03:15
我发现了问题的原因:
显然,我需要在域的根文件夹中安装composer和mailgun依赖项,而不是全局安装。
我改变了通往这个的路径,因为我在一个论坛上发现了这个:
$client = new \GuzzleHttp\Client();
这给了我一个错误:
Catchable fatal error: Argument 2 passed to Mailgun\Mailgun::__construct() must be an instance of Http\Client\HttpClient, instance of GuzzleHttp\Client我通过在终端中运行这个命令来修正这个问题:
php composer.phar require php-http/guzzle6-adapter:^1.0并将路径更改为原始路径:
$client = new \Http\Adapter\Guzzle6\Client();因此,现在mailgun使用以下代码工作得很好:
require 'vendor/autoload.php';
ini_set('display_errors', 'On');
$client = new \Http\Adapter\Guzzle6\Client();
define('MAILGUN_KEY', 'key-xxxxxxxxxx');
define('MAILGUN_DOMAIN', 'my-domain.nl');
$mailgun = new \Mailgun\Mailgun(MAILGUN_KEY, $client);
$mailgun->sendMessage(MAILGUN_DOMAIN, [
'from' => 'my@email.com',
'to' => 'your@e-mail.com',
'subject' => 'This is a test e-mail',
'html' => "
Hello,</br></br>
This is a test."
]);https://stackoverflow.com/questions/39519883
复制相似问题