Sendgrid-php: Pdf attachment got corrupted

Created on 29 Aug 2018  路  5Comments  路  Source: sendgrid/sendgrid-php

Hi, i've been searching everywhere for the solutions to fix it but i still can't send email with pdf attachment.

$file_encoded = base64_encode(file_get_contents($attachment));
            $email->addAttachment(
                $file_encoded,
                "application/pdf",
                "another.pdf",
                "attachment"
            );

i'm using this code to attach pdf file but it's not working, please someone help, thank you

easy help wanted help wanted bug docs update up for grabs up-for-grabs

Most helpful comment

@rcooo Thank you so much!
image

They might want to change that in their PHP examples..

All 5 comments

Hi @buddyy93,

Could you please send your attachment to [email protected] so that we can try and reproduce the error?

Thanks!

With Best Regards,

Elmer

Hi @buddyy93, it looks like your content get's base64 encoded twice. Just fiddling around with this library to add ICS invite as a attachment. I found out that the content gets encoded twice it it was already encoded, so this should work for you:

$file_encoded = file_get_contents($attachment);
$email->addAttachment(
    $file_encoded,
    "application/pdf",
    "another.pdf",
    "attachment"
);

@rcooo Thank you so much!
image

They might want to change that in their PHP examples..

Thanks for the heads up @nbarkat!

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FilipLukac picture FilipLukac  路  4Comments

mwsasser picture mwsasser  路  3Comments

bjornmann picture bjornmann  路  3Comments

iamanupammaity picture iamanupammaity  路  4Comments

Aubynj picture Aubynj  路  3Comments