sendgrid / sendgrid-php

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

Sendgrid php library incompatible with PHP 8.1 #1072

Open charliepfm opened 2 years ago

charliepfm commented 2 years ago

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

jonathonbyrdziak commented 2 years ago

following. +1

ncovercash commented 2 years ago

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 commented 2 years ago

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

childish-sambino commented 2 years ago

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.