sendgrid-php icon indicating copy to clipboard operation
sendgrid-php copied to clipboard

Sendgrid php library incompatible with PHP 8.1

Open charliepfm opened this issue 4 years ago • 4 comments

Summary

Heroku Platform with SendGrid provisioned. Emails have been going out fine for many months. Heroku pushed PHP v8.1 into all Dynos (instances) on Dec 10, 2021. A release of our application was published today (Dec 14) and now all attempts to send emails with the SendGrid API fail.

Steps to Reproduce

  1. Use existing code to attempt to send a simple email with SendGrid with a PHP 8.1 environment
  2. The error message received is as follows: "Return type of SendGrid\Mail\Mail::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange (and so on)

Code Snippet

  function sendvcodeemail ($thevalue, $destemail) {
    $email = new \SendGrid\Mail\Mail(); 
    $email->setFrom(<specific an email address that has been verified>, <some name string>);
    $email->setSubject("Verification code for <application>");
    $email->addTo($destemail, "User");
    $cmsg = "Your verification code is " . $thevalue . PHP_EOL . 
            "This code is only valid for a few minutes, please use it quickly";
    $email->addContent("text/plain", $cmsg);
    $sendgrid = new \SendGrid(getenv('SENDGRID_APIKEY'));
    try {
        $response = $sendgrid->send($email);
        $_SESSION['justsomething'] = $response;
    } catch (Exception $e) {
        $_SESSION['justsomething'] = 'there was an error sending email';
    };
  };

sendvcodeemail("123456","<a valid email destination>");

Technical details:

sendgrid-php version: 7.11 (using composer.json -> require: {"sendgrid/sendgrid": "^7", .... php version: According to build log on Heroku deploy - version 8.1

charliepfm avatar Dec 14 '21 18:12 charliepfm

following. +1

jonathonbyrdziak avatar Dec 16 '21 18:12 jonathonbyrdziak

Here are the specific lines/files with these errors:

Deprecated: Return type of SendGrid\Mail\Mail::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/cloud-screen.com/src/vendor/sendgrid/sendgrid/lib/mail/Mail.php on line 1837

Deprecated: Return type of SendGrid\Mail\Personalization::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/cloud-screen.com/src/vendor/sendgrid/sendgrid/lib/mail/Personalization.php on line 280

Deprecated: Return type of SendGrid\Mail\EmailAddress::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/cloud-screen.com/src/vendor/sendgrid/sendgrid/lib/mail/EmailAddress.php on line 183

Deprecated: Return type of SendGrid\Mail\Subject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/cloud-screen.com/src/vendor/sendgrid/sendgrid/lib/mail/Subject.php on line 63

Deprecated: Return type of SendGrid\Mail\Content::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/cloud-screen.com/src/vendor/sendgrid/sendgrid/lib/mail/Content.php on line 106

ncovercash avatar Jan 13 '22 01:01 ncovercash

It looks like #1066 should have fixed this (effective as of v7.11.1), however, it does not work on my tests.

ncovercash avatar Jan 13 '22 01:01 ncovercash

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

childish-sambino avatar Feb 18 '22 19:02 childish-sambino