【问题标题】:Guzzle Http not found mailgunGuzzle Http 未找到 mailgun
【发布时间】:2016-09-15 20:32:35
【问题描述】:

我正在尝试在我的 php 项目中使用 Mailgun。 我已经安装了所有必要的组件:

  • 作曲家
  • 狂饮 6

这是我测试电子邮件服务的 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 并使其全球可用。我应该这样做还是将它们安装在我的域的根文件夹中?

【问题讨论】:

  • 不应该是$client = new \GuzzleHttp\Client();
  • 这只是返回一个不同的错误:Fatal error: Class 'GuzzleHttp\Client'而不是另一个......所以还没有运气......
  • “使其全球可用”是什么意思?
  • 此服务器上有多个域。我安装了该软件包并使其对服务器上的每个用户都可执行,因此我不需要为每个域单独安装它

标签: php composer-php centos7 mailgun guzzle6


【解决方案1】:

我找到了问题的原因:

显然我需要在我的域的根文件夹中而不是全局安装 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." 
    ]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 2015-10-10
    • 2015-07-16
    • 1970-01-01
    • 2019-09-07
    相关资源
    最近更新 更多