How to send image attachment?
Closed this issue · 8 comments
Trying to send image attachment, setting it as attachments[n].content => file_get_content(file)
but get an error: Error: Malformed UTF-8 characters, possibly incorrectly encoded
Hey @yus-ham, can you share your implementation code with me?
You could encode your file contents like:
$content = file_get_contents('file.pdf');
$content = utf8_encode($content);
@jayanratna, here code you can look https://replit.com/@supham/php-resend-email?v=1
now i can send the attachment, but gmail seem received broken image
I am playing around with resend right but I use curl with php and I am facing the same issue with attachments. (I can't use the library because the app is PHP 5.3 and this library needs php 7.x)
I am trying to send a PDF file. First I tried to use get_file_contents only. This didn't work = produces empty json body.
utf8_encode kinda works but the PDF is not readable (empty). Are there any other ways? It would be cool that we could send base64 encoded string instead of fiddling around with encodings. I tried base64 but the file arrives totally broken (not decoded base64 string)
Any ideas?
@yus-ham thanks for sharing your code. I'll take a look.
@millsoft thanks for the valuable insight. I agree with you. Having the ability to send a base64 encoded string would solve all issues.
@bukinoshita Do you think we can add support for base64 encoded strings?
@yus-ham sorry for the delay on resolving this for you. I had a look at your provided code and it looks like your attachments are already hosted on an external URL. This means that you can use the path
property instead of the content
property when sending an attachment. For example:
$resend->emails->send([
'from' => 'from@example.com',
'to' => 'to@example.com',
'subject' => 'hello world',
'text' => 'it works!',
'attachments' => [
[
'filename' => 'invoice.pdf',
'path' => 'https://foo.bar/dir/file.pdf'
]
]
]);
I hope this helps. Let me know how it goes.
@jayanratna after using path
, it just works, thankyou
This works for me.
"attachments" => [
[
"filename" => "invoice.pdf",
"content" => base64_encode($pdf)
]
]