Skip to content

SendGrid::send() fails with Mail object due to type mismatch in Client::makeRequest() #1125

@GOvidiu20

Description

@GOvidiu20

Using the SendGrid::send() method with a \SendGrid\Mail\Mail instance results in the following error:

SendGrid\Client::makeRequest(): Argument #3 ($body) must be of type ?array, SendGrid\Mail\Mail given

This occurs even though send() is documented to accept a Mail object. It appears that the send() method no longer serializes the object internally via jsonSerialize() before passing it to Client::post().

Workaround
This works just fine:

$sg = new SendGrid('your-api-key');
$response = $sg->client->mail()->send()->post($mail->jsonSerialize());

Environment:
PHP: 8.4 (dev)
sendgrid/sendgrid: 8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions