38

I am trying to use Mandrill to send emails via my Laravel framework, however I am receiving the following error:

FatalErrorException in MandrillTransport.php line 114: Class 'GuzzleHttp\Client' not found

I have installed Guzzle using the following command in Terminal:

"guzzlehttp/guzzle": "~4.0"

According to Laravel's documentation I need to add "guzzlehttp/guzzle": "~4.0" to my composer.json file, but I'm not sure if where I have placed it is correct as I still see the error.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*",
        "illuminate/html": "^5.0",
        "guzzlehttp/guzzle": "~4.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Here is the list of packages my application has, notice that guzzle has a different version: 4.2.3 which i've also tried updating to but still get the same error. list of packages installed

InvalidSyntax
  • 9,131
  • 20
  • 80
  • 127
  • How to solve this issue? – Unbreakable Oct 14 '15 at 06:22
  • Laravel 5.8: Guzzle ^6.0 (https://github.com/laravel/framework/blob/v5.8.38/composer.json#L124) Laravel 6: Guzzle ^6.3.1|^7.0.1(https://github.com/laravel/framework/blob/v6.20.2/composer.json#L126) Laravel 7: Guzzle ^6.3.1|^7.0.1 (https://github.com/laravel/framework/blob/v7.29.2/composer.json#L132) Laravel 8: Guzzle ^6.5.5|^7.0.1 (https://github.com/laravel/framework/blob/v8.12.3/composer.json#L135) – saber tabatabaee yazdi Feb 27 '23 at 20:10

10 Answers10

36

Open up your terminal at the root of your project and enter

composer require guzzlehttp/guzzle

It worked for the mailgun API. For some reason, the suggested method at the laravel's mail doc. You may install this package to your project by adding the following line to your composer.json file

"guzzlehttp/guzzle": "~5.3|~6.0"

doesn't make the composer download the Guzzle source codes. By the way, I didn't find out what | means in determining the version. This command just downloads the PSR code.

In this moment, the solution may work. However, be aware of compatibility issues. Because the command would install the latest stable version, not the suitable one.

Mr. Taumal
  • 94
  • 1
  • 8
shampoo
  • 1,173
  • 12
  • 22
14

If you're using Laravel when you run into this error, just run:

composer require guzzlehttp/guzzle

And try again.

Grant
  • 5,709
  • 2
  • 38
  • 50
7

After updating your composer.json file you need to run the update command to resolve and install your dependencies:

composer update

or, if composer isn't in your path:

php composer.phar update
Paul
  • 139,544
  • 27
  • 275
  • 264
  • 1
    I've tried this, but the issue still persists. Here is the output from `composer update`: `Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files Generating optimized class loader` – InvalidSyntax Jul 05 '15 at 04:24
  • @Imran After seeing your updates it looks like Guzzle is installed correctly, but it is not being autoloaded. Your composer autoloader should have an entry for GuzzleHttp (check in `vendor/composer/autoload_psr4.php` and let me know if there is a line for `GuzzleHttp` ). I'm only familiar with composer, not Laravel, but it looks like you should run the command `php artisan dump-autoload` to regenerate Laravel's autoloader. – Paul Jul 05 '15 at 04:49
  • I have tried using `php artisan dump-load` but I get a 'Command not defined' error. I have also tried `composer dump-autoload` which generated the autoload files but I am still receiving the same Class not found error in my original question. – InvalidSyntax Jul 05 '15 at 22:54
2

Did you try :

artisan clear-compiled 

or if artisan is not available try to remove compiled.php if exist (in vendor directory) and launch composer dumpautoload

Ju Chépa
  • 67
  • 10
  • Yes I have tried this, but I still receive the error. There is no compiled.php file in my vendor directory and I have already ran `composer dump-autoload` – InvalidSyntax Jul 07 '15 at 00:29
  • Maybe you should remove your composer.lock and vendor folder and try to reinstall all if it's possible. – Ju Chépa Jul 07 '15 at 05:40
2

I had the same issue. I used an old version in order to work. It's not working anymore since version 4. It works on version 3.8.1

So you can add "guzzlehttp/guzzle": "~3" to works

Larzack
  • 21
  • 2
1

simple in my case add "guzzlehttp/guzzle": "^6.3" in composer.json require object as mentioned below

"require": {
        "php": ">=7.0.0",
        "ext-gd": "*",
        "barryvdh/laravel-cors": "^0.11.2",
        "barryvdh/laravel-dompdf": "^0.8.1",
        "dingo/api": "2.0.0-alpha1",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "league/flysystem-aws-s3-v3": "~1.0",
        "predis/predis": "^1.1",
        "tymon/jwt-auth": "dev-develop"
    }, 

than run composer update in project root using terminal than its working fine.

Muhammad Sulman
  • 1,611
  • 1
  • 19
  • 25
0

I am oblivious to why this worked for me, I saw this in a forum somewhere

I just added this captcha generator to the composer.json file

"mews/captcha": "~2.0.",

added it to all the require package

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "laravelcollective/html": "5.1.*",
    "laracasts/flash": "~1.3",
     "mews/captcha": "~2.0.",
    "guzzlehttp/guzzle": "~4.0"
    },

If someone knows why this worked it would really scratch the itch in my brain.

Gokigooooks
  • 794
  • 10
  • 20
0

I got this error when I tried running my code outside of the Laravel framework while testing in a stand alone file. It worked for me when I moved it inside a controller.

boateng
  • 910
  • 11
  • 21
0

You can solve this problem to add "mews/captcha": "1.0.1" and "guzzlehttp/guzzle": "~4.0" to your composer.json file. And then you need run composer update command on your terminal.

I have tried on Laravel 4. It works for me.

Goktug Gumus
  • 129
  • 4
0

Try updating your composer to latest version might end sorting your problem. This worked out for me. Ubuntu/Linux users use this tutorial in Digital ocean

Joshua Johns
  • 340
  • 1
  • 3
  • 10