39

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

2

11 Answers 11

41

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.

Sign up to request clarification or add additional context in comments.

Comments

15

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

composer require guzzlehttp/guzzle 

And try again.

Comments

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 

3 Comments

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
@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.
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.
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

2 Comments

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
Maybe you should remove your composer.lock and vendor folder and try to reinstall all if it's possible.
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

Comments

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.

Comments

1

I had the exact same issue. I resolved it by adding

require 'vendor/autoload.php'

to the top of the file.

My autoload.php includes theses lines from Guzzle

'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzlehttp/psr7/src'),

'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),

'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),

"Autoload is a method to load and use classes. Using Autoload, we can load and call classes everywhere instead of including classes at the beginning of each PHP file. Therefore, we don’t need to load all classes in the library for all PHP files." quoted from - https://metabox.io/composer-and-autoload-in-php/

Comments

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.

1 Comment

Could be because mews/captcha require the dependency.
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.

Comments

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.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.