1

Let me explain first what I'm trying to achieve 1. User submits a form requesting membership, app sends a mail to user acknowledging user's request 2. Admin approves or denies the request, app sends mail to user notifying them

With mailtrap, i have been able to make this work locally. Moving to production, I have switched to using Sparkpost following the steps in sending mail with sparkpost tutorial But I keep getting the error

Class 'GuzzleHttp\Client' not found in TransportManager.php (line 185)

I can see the guzzle folder inside vendor folder after running composer require guzzlehttp/guzzle

"require": {
    "php": ">=5.6.4",
    "guzzlehttp/guzzle": "^6.3",
    "laravel/framework": "5.4.*",
    "laravel/tinker": "~1.0"
},

I just don't understand why i'm getting this error or how to fix it. Need help resolving this issue

Mena
  • 1,873
  • 6
  • 37
  • 77

2 Answers2

0

You may want to ensure the you first have a require './vendor/autoload.php included (which should be the case in Laravel by default).

If autoload.php is already included and you still get this error, then according to this filed bug - https://github.com/SparkPost/php-sparkpost/issues/37, you will need to manually run

php composer.phar require guzzlehttp/guzzle

DeadLock
  • 448
  • 3
  • 11
  • I have autoload.php in my vendor's folder. Is that what you mean? Or is there a file i need to have that line inside? Btw, i already ran `composer require guzzlehttp/guzzle` manually and in added it inside my composer.json file – Mena Dec 18 '17 at 10:24
  • You need to verify that there is a `require ./vendor/autoload.php` written in some part of the invoked code path. Just having the file in the folder will not help. When you do a `require` of this file, it will in-turn load all the classes of the installed dependencies into your code. Once these classes are included, your compiler will stop complaining that the Class is missing when you use it. – DeadLock Dec 18 '17 at 10:33
  • MemberController is were the mails are being intiated, sp going by you response I added `require './vendor/autoload.php'` at the very top before everything else. Have a very strong feeling I'm doing it wrong but is that the right thing to do? The error is the same as before – Mena Dec 18 '17 at 10:46
  • If you are manually adding it to your controller, you will have to give the relative path to `vendor/autoload.php`. You may also want to keep an eye on the error.log file of your server to fix dependent errors. – DeadLock Dec 18 '17 at 10:51
0

Finally made my code work by doing the following

Initially i ran composer require guzzlehttp/guzzle to add guzzlehttp/guzzle to require section of composer.json file

Secondly, I ran composer update

Lastly, I uploaded my files from my local server to the production server. Then I added use GuzzleHttp\Client to my mail controller and everything worked well.

I think what i was missing earlier was not running composer update after requiring guzzlehttp/guzzle

Mena
  • 1,873
  • 6
  • 37
  • 77