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

Base64 Encoded PDF Fails

Open matsolastrom opened this issue 2 years ago • 3 comments

When using the SendSmtpEmailAttachment.php to send a PDF, sometimes the preg_match on line 266 fails without reason. Please remove this preg check or fix it. I am using a base_64 encoded PDF and it works fine to send it if I comment out the preg_match.

matsolastrom avatar Aug 30 '23 14:08 matsolastrom

reported this bug 5 years ago and still not fixed :( https://github.com/sendinblue/APIv3-php-library/issues/56

mirsch avatar Sep 11 '23 09:09 mirsch

I found a work around about this bug. I use this lib on Symfony app. Not use SendSmtpEmailAttachment and add an array to the setAttachment() method.

Doesn't work

foreach ($email->getAttachments() as $file) {
    $sendSmtpEmailAttachment = (new SendSmtpEmailAttachment())
        ->setName($file->getFilename())
        ->setContent(base64_encode($file->getContent()));

    $attachments[] = $sendSmtpEmailAttachment;
}

$sendSmtpEmail->setAttachment($attachments);

Works like a charm


$attachments = [];
foreach ($email->getAttachments() as $file) {
    $attachments[] = [
        'name' => $file->getFilename(),
        'content' => base64_encode($file->getContent()),
    ];
}

$sendSmtpEmail->setAttachment($attachments);

[!WARNING] You need to check what you receive before. Because you avoid that regex with that solution.

StevenRenaux avatar Jun 20 '24 15:06 StevenRenaux

@StevenRenaux Thank you so much ! this fixed it for me !

DennisdeBest avatar Jul 21 '24 14:07 DennisdeBest