This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Attach PDF file to Email

vishp wrote on 2014-06-15:

I want to attach the generated pdf to php mail, can someone pl help if something like this is possible

$pdf = $client->convertURI('');
echo $pdf;

Instead of echo pdf, i want to send this pdf file to a email with attachment in php

Thanks in Advance
support wrote on 2014-06-16:
vishp wrote on 2014-06-17:

Thanks for the quick reply, tried out those links..
I was able to get email with pdf as attachement, but its corrupted..

Please help on finding the solution.
support wrote on 2014-06-17:

Make your PHP code send an email with PDF to and we will look into it.
vishp wrote on 2014-06-17:

we sent the email, with subject 'Form Username : vishp'
please look into it.
support wrote on 2014-06-18:

I updated the code at Can you try again now?
vishp wrote on 2014-06-20:

we tried the updated code.. copied the code from this link
and just changed these two lines..
$client = new Pdfcrowd($username, $apikey);
$to = '';

save it to a php file.. and upload to server..

we use a simple web hosting server, dont have any seperate webservers like apache

after the url path address with php file is entered in browser, getting pdf as attachment in the mail to recipient address, but its still corrupted.
support wrote on 2014-06-23:

That's strange. It did not work for me at first either but after I added an empty line before line 38 (see here), it started to work. Try to add more empty lines to see if it helps but if it won't, I'm out of ideas what to try next, sorry.
glassbaron wrote on 2014-07-23:
Thanks for posting this thread and thank you Jaroslav for helping me through this problem. I tried both code examples and eventually when I removed all the white space AND all the tabs from the $message the $pdf generated correctly.
vishp wrote on 2014-07-23:

Thanks for the support, This is working fine now, i am able to attached PDF to mail , This is the fix I applied
"I added an empty line before line 38" from the above post