sendgrid-php: Provide solution for "Class 'SendGrid\Client' not found" error, which occurs when files are missing
I am getting the following error on form submission
Class 'SendGrid\Client' not found
I am upgrading from v2 to v3 (v2 worked fine) and I am not using composer.
Any thoughts?
require_once($this->config->paths->root . 'api/sendgrid/lib/loader.php');
if ($this->input->post->action == 'enquiryForm') {
if ($_POST['products']) {
foreach ($_POST['products'] as $item) {
if (is_array($item)) {
$products[] = $item;
}
}
}
if ($_POST['formFields']) {
parse_str($_POST['formFields'], $user_details);
}
ob_start();
require_once('../../api/template--enquiry.php');
$body = ob_get_contents();
ob_end_clean();
$email = new \SendGrid\Mail\Mail();
$email->setFrom($user_details['email'], null);
$tos = [
"rich@****.***" => null
];
$email->addTos($tos);
$email->setSubject("Sending with SendGrid is Fun");
$email->addContent(
"text/html", $body
);
$sendgrid = new \SendGrid(getenv('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'));
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";
}
}
I am using PHP 7.1 and latest commit 2889b96 (although as I am not using composer I had to add the following push requests: https://github.com/sendgrid/sendgrid-php/pull/633
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 22 (16 by maintainers)
Commits related to this issue
- Fix #644: Remove loader.php loader.php appears to be unused, except for a stray reference in CONTRIBUTING.md. Actually, that reference is misleading, since composer is required in order to provide th... — committed to mkasberg/sendgrid-php by mkasberg 8 years ago
- Fix #644: Remove loader.php loader.php appears to be unused, except for a stray reference in CONTRIBUTING.md. Actually, that reference is misleading, since composer is required in order to provide th... — committed to mkasberg/sendgrid-php by mkasberg 8 years ago
if you’re like me and hate composer (don’t even get me started) you can get this to work so- just so you know … everyone here is wrong … “they” (SendGrid) simply forgot to bundle everything properly, took out \SendGrid\Email() and replaced it with \SendGrid\Mail\Mail() and so the callers are slightly different … i.e.
but you it this way you still need “php-http-client-master” and “sendgrid-php-master” (both repos) and the
/lib/loader.phpin “sendgrid-php-master” needs these two lines adding at the endIncidentally I also edited
sendgrid-php-master\sendgrid-php.phpto this < ? php require DIR . ‘/lib/loader.php’; ? >