sendgrid/sendgrid-php

Getting error in configure email ( Exception: Class 'SendGrid\Mail\Mail' not found )

Closed this issue · 8 comments

Issue Summary

I am trying to configure Web API of sendgrid email but not done step mentions bellow which i used to configer

Steps to Reproduce

  1. log in to Sendgrid Account
  2. go to the sidebar section of the Integration issue.
  3. there are few steps I followed and select option to integrate without composer section
  4. Generate API Key and pass in .env file
  5. I have PHP version of 7.2
  6. Source code of sending mail shared bellow

Code Snippet

require_once(APPPATH.'libraries/sendgrid-php-7.9.2/sendgrid-php.php');
$email = new \SendGrid\Mail\Mail();
$email->setFrom('info@aipsonlineclasses.com', 'AIPSTeam');
$email->setSubject('TEST SENGRID MAIL');
$email->addTo('vijaypippal1988@gmail.com');
// $email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent("text/html", '

Hello vijay Mail Working OK

');
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}

Exception/Log

ERROR - 2021-04-16 11:04:33 --> Severity: error --> Exception: Class 'SendGrid\Mail\Mail' not found /home/bvqcpzeodnkd/public_html/aipsonlineclasses.com/application/controllers/Home.php 41

LIne No. 41 is in above code : $email = new \SendGrid\Mail\Mail();

Technical details:

  • sendgrid-php version: 7.9.2
  • php version: 7.2

@testworking2705 I would verify that the path to sendgrid-php.php is correct. Also, I went ahead and removed the screeenshot that shows your API key in the description. I strongly recommended you refresh the key.

yes, I am already double sure with path of sendgrid-php.php .
but, am getting this the error show above.

Hello @testworking2705,

Can you please try installing using the instructions here? Thank you!

With best regards,

Elmer

Any reason you are using this:

require_once(APPPATH.'libraries/sendgrid-php-7.9.2/sendgrid-php.php');

opposed to an artisan install and this ?:

require 'vendor/autoload.php';

Hello @testworking2705,

Can you please try installing using the instructions here? Thank you!

With best regards,

Elmer

i already flow these steps to install but getting error.

Any reason you are using this:

require_once(APPPATH.'libraries/sendgrid-php-7.9.2/sendgrid-php.php');

opposed to an artisan install and this ?:

require 'vendor/autoload.php';

the reason is that am using Codeigniter framework with cpanel but thers is no terminal so that, i am using this andnot using
composer..

the reason is that am using Codeigniter framework with cpanel but thers is no terminal so that, i am using this andnot using
composer..

Could you develop locally, or in a virtual machine - like VirtualBox - to get the path issue resolved, then upload all the files once it's working?

If you have to hack the include and paths, you'll likely be able to see when you have access to the class like so : https://electrictoolbox.com/php-get-available-classes/

Just checking in @testworking2705. Were you able to give @JeremyHutchings suggestion a try? Thanks!