RegEx in SendSmtpEmailAttachment::setContent fails
the RegEx in SendSmtpEmailAttachment::setContent does not evaluate to true
I tried $content = base64_encode(file_get_contents($filepath));
which evaluates to false and
$content = chunk_split(base64_encode(file_get_contents($filepath)));
returns 0
So InvalidArgumentException is thrown all the time.
Attachment is an PDF File ca. 50-60kb
Same problem ... :-(
Hello everyone,
As we encountered the same bug with a 480Kb jpg attachment, it appears that the validation process in class SendSmtpEmailAttachment is the source of the error.
Indeed the statement !preg_match("/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/", $this->container['content']) used several times in the code raises the PREG_JIT_STACKLIMIT_ERROR (code 6 returned from preg_last_error()) documented in php manual.
Disabling PCRE JIT wiht statement ini_set('pcre.jit', '0'); for debugging purpose showed that preg_match raised the PREG_RECURSION_LIMIT_ERROR (code 3) that we could pass by raising the limit with ini_set('pcre.recursion_limit', '1000000000');
A solution would be to validate attachment content with false !== base_64_decode($content, $strict = true)
Up, problem still here, I can't join a pdf
Up, same problem for me with a 75Ko pdf attachment.
When i tried to convert the base64 to pdf document with an online converter, the pdf is ok
Is this API dead?? Nobody from Sendinblue to handle it?
You can work around this by including the base64 content in the constructor, which doesn't run it through the regex check (which causes the PREG_JIT_STACKLIMIT_ERROR).
$content = base64_encode(...);
$attachment = new SendSmtpEmailAttachment(["name" => $terms->getName(), "content" => $content]);
Not sure why they would run large attachments through a regex in the first place, tbh.
For work around see https://github.com/getbrevo/brevo-php/issues/11#issuecomment-2180956969