Guzzle Http 未找到 mailgun

Guzzle Http not found mailgun

我正在尝试在我的 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

为什么在 composer.json 中安装和需要 Guzzle6 时仍然找不到它?

编辑:

也许是一些重要的信息,我已经在 /usr/local/lib 中安装了 composer 和 Guzzle 并使其在全球范围内可用。我应该这样做还是将它们安装在我域的根文件夹中?

我找到了问题的原因:

显然我需要在我的域的根文件夹中而不是全局安装 composer 和 mailgun 依赖项。

我把 guzzle 的路径改成了这个,因为我在论坛上发现了这个:

$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." 
    ]);