I have the following situation:
I am attaching a pdf file , which is in google drive using phpmailer . What happens to me is that when I send the email with the attachment, when I download the file to the machine it tells me that it cannot be opened and if I try to open it from the Gmail client it opens it but not as a pdf document but rather as a document that can be edited.
When I try to open the pdf document with the pdf reader it gives me the following message:
The file type HTML document (text/html) is not allowed
The code I'm using to attach the file is as follows:
File reading:
$path = "https://drive.google.com/open?id=18hMk_9TmC3dsCjwe0RQ1Ka-qaqs4uMcD"
$fichero = file_get_contents($path);
phpmailer methods for attachment
$xmail->addStringAttachment($fichero,comprobante.pdf);
Thanks.
I already managed to solve the problem I had. I leave you here how I solved it in case someone else gets this error that he gave me. I did the solution using the same google-drive api that has an example to download the files. Instead of using the file_get_contents() method, use the example in the api . Here is the code:
$fileId (it is the id of the file in google-drive)
Google-Drive example link