sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 623 forks source link

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

Closed testworking2705 closed 3 years ago

testworking2705 commented 3 years ago

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:

shwetha-manvinkurke commented 3 years ago

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

testworking2705 commented 3 years ago

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

thinkingserious commented 3 years ago

Hello @testworking2705,

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

With best regards,

Elmer

JeremyHutchings commented 3 years ago

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';

testworking2705 commented 3 years ago

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.

testworking2705 commented 3 years ago

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

JeremyHutchings commented 3 years ago

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/

thinkingserious commented 3 years ago

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