getbrevo / brevo-php

A fully-featured PHP API client to interact with Brevo.
https://developers.brevo.com/
MIT License
45 stars 19 forks source link

Base64 Encoded PDF Fails #11

Open matsolastrom opened 1 year ago

matsolastrom commented 1 year ago

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.

mirsch commented 1 year ago

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

StevenRenaux commented 2 months ago

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.

DennisdeBest commented 1 month ago

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