s-ichikawa / laravel-sendgrid-driver

This library can add sendgrid driver into the laravel's mail configure.
MIT License
391 stars 91 forks source link

Issue with the `attachments` element in the array passed to `sendgrid` method #161

Closed l-alexandrov closed 2 years ago

l-alexandrov commented 2 years ago

Currently when we pass an element with attachments key in the array to the sendgrid method and send the email we receive:

array_merge(): Argument #1 must be of type array, null given

/srv/some-fancy-app/vendor/s-ichikawa/laravel-sendgrid-driver/src/Transport/SendgridTransport.php(243): array_merge()

1 /srv/some-fancy-app/vendor/s-ichikawa/laravel-sendgrid-driver/src/Transport/SendgridTransport.php(76): Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport->setParameters()

2 /srv/some-fancy-app/vendor/symfony/mailer/Transport/AbstractTransport.php(68): Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport->doSend()

3 /srv/some-fancy-app/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(521): Symfony\Component\Mailer\Transport\AbstractTransport->send()

Example code:

 public function build()
 {
      $sendGridPayload = [
                  'attachments' => ['content' => '...', 'filename' => '...', 'type' => '...']
      ];
        return $this
            ->subject('...')
            ->sendgrid($sendGridPayload);
}

I think the issue is when adding support to Laravel 9 you've removed the attachments class member initialization and now it remains uninitalized.

s-ichikawa commented 2 years ago

Merged it and tagged 4.0.1. Thank you for fixed!