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:
Hello

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

$pdf = $client->convertURI('http://www.google.com/');
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:
Hello,

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:
Hello,

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

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

I updated the code at https://gist.github.com/pdfcrowd/2891593. Can you try again now?
vishp wrote on 2014-06-20:
Hello,

we tried the updated code.. copied the code from this link https://gist.github.com/pdfcrowd/2891593
and just changed these two lines..
$client = new Pdfcrowd($username, $apikey);
$to = 'recipient@example.com';

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:
Hello,

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:
Hello,

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

Thanks
Vish