luisdalmolin / laravel-mandrill-driver

Mandrill mail driver for Laravel for version 6+
MIT License
79 stars 38 forks source link

Bcc recipients not delivery #29

Closed BorjaCL closed 2 years ago

BorjaCL commented 2 years ago

Since updating the package to work with Laravel 9, none of the bcc recipients are receiving emails. Is the same happening to anyone else?

c-delouvencourt commented 2 years ago

Same here the mail does not sent when cc or bcc is set

wblommaert commented 2 years ago

I compared v3.1.0 to v4.0.0 of this package and noticed that in v4.0.0 the to parameter is no longer passed, which is where cc and bcc recipients were set in the past.

v3.1.0 used the following:

    public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
    {
        $this->beforeSendPerformed($message);

        $response = $this->client->request('POST', 'https://mandrillapp.com/api/1.0/messages/send-raw.json', [
            'form_params' => [
                'key' => $this->key,
                'to' => $this->getTo($message),
                'raw_message' => $message->toString(),
                'async' => true,
            ],
        ]);

        $message->getHeaders()->addTextHeader(
            'X-Message-ID', $this->getMessageId($response)
        );

        $this->sendPerformed($message);

        return $this->numberOfRecipients($message);
    }

note the 'to' => $this->getTo($message), when building the form_params array:

    protected function getTo(Swift_Mime_SimpleMessage $message)
    {
        $to = [];

        if ($message->getTo()) {
            $to = array_merge($to, array_keys($message->getTo()));
        }

        if ($message->getCc()) {
            $to = array_merge($to, array_keys($message->getCc()));
        }

        if ($message->getBcc()) {
            $to = array_merge($to, array_keys($message->getBcc()));
        }

        return $to;
    }

in v4.0.0 however this is missing, as shown below:

    protected function doSend(SentMessage $message): void
    {
        $message = $this->setHeaders($message);

        $this->mailchimp->messages->sendRaw([
            'raw_message' => $message->toString(),
            'async' => true,
        ]);
    }

I currently don't have time this week to try and fork this repository to see if adding the getTo method again would resolve this issue, so if anyone else can try that would be awesome. Else I'll give it a go this weekend when I have some time to look at this.

wblommaert commented 2 years ago

@BorjaCL @c-delouvencourt I've opened a PR #34 that adds the behaviour from v3.x.x. Feel free to try out my fork and see if that fixes this issue for you both as well. If so, hopefully we can get it merged soon. Also, always happy to hear feedback!

luisdalmolin commented 2 years ago

PR is merged and this should be working on 4.0.2.