Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dikesh 's avatar

How to send pdf file in gmail api

how to send file in gmail

			$pdfContent = $pdf_file->output();

            $pdfBase64 = base64_encode($pdfContent);

		 $emailContent .= "Content-Type: application/pdf; name=\"invoice.pdf\"\r\n";

            $emailContent .= "Content-Disposition: attachment; filename=\"invoice.pdf\"\r\n";

		$emailContent .= "Content-Transfer-Encoding: base64\r\n\r\n";

                $emailContent .= chunk_split($pdfBase64);

I used this code to send a file via the Gmail API, but I received this type of PDF code in the email Content-Type: application/pdf; name="invoice.pdf" Content-Disposition: attachment; filename="invoice.pdf" Content-Transfer-Encoding: base64 MIME-Version: 1.0 JVBERi0xLjcKMSAwIG9iago8PCAvVHlwZSAvQ2F0YWxvZwovT3V0bGluZXMgMiAwIFIKL1BhZ2Vz IDMgMCBSID4+CmVuZG9iagoyIDAgb2JqCjw8IC9UeXBlIC9PdXRsaW5lcyAvQ291bnQgMCA+Pgpl bmRvYmoKMyAwIG9iago8PCAvVHlwZSAvUGFnZXMKL0tpZHMgWzYgMCBSCjEyIDAgUgpdCi9Db3Vu dCAyCi9SZXNvdXJjZXMgPDwKL1Byb2NTZXQgNCAwIFIKL0ZvbnQgPDwgCi9GMSA4IDAgUgovRjIg OSAwIFIKPj4KL0V4dEdTdGF0ZSA8PCAKL0dTMSAxMCAwIFIKL0dTMiAxMSAwIFIKPj4KPj4KL01l ZGlhQm94IFswLjAwMCAwLjAwMCA1OTUuMjgwIDg0MS44OTBdCiA+PgplbmRvYmoKNCAwIG9iagpb L1BERiAvVGV4dCBdCmVuZG9iago1IDAgb2JqCjw8Ci9Qcm9kdWNlciAo/v8AZABvAG0AcABkAGYA IAAyAC4AMAAuADMAIAArACAAQwBQAE how to fixed?

0 likes
1 reply
sarveshnaik123's avatar

hi even am facing the same issue while testing the google gmail api in my postman tool

Please or to participate in this conversation.