PHP Email the PDF file - php

I am using the following code to write my form data into a PDF file now how can I email that PDF file using a simple PHP code as an attachment?
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, $_POST['first_name']);
$pdf->Output();
mail('me#mydomain.com','subject','message')
?>
This code is download the PDF but instead I need the file to be emailed as an attachment.

Related

Save PDF file as PDF not PHP

I am using using FPDF to create pdf file. But it show extension as php not pdf. When i download the file in mobile it show .php file. Now how can I convert the php extension to pdf
Here index.php file
Click Here
Here pdf.php file
<?php
require ("fpdf/fpdf.php");
$name = "Amit Samadder";
$pdf = new FPDF('p','mm','A4');
$pdf->AddPage();
$pdf->SetFont("Arial","B","20");
$pdf->Cell(100,10, $name, 1,0, "C");
$pdf->Output();
?>
Have a look at http://fpdf.org/en/doc/output.htm
You need to change this line:
$pdf->Output();
To:
$pdf->Output('D', 'myfile.pdf');

Execute two fpdf pdf files at once?

I have a requirement where two pdfs need to be created at once. A for loop will not work as one file is going to be a certificate pdf. The next file is going to be an Invoice pdf. I know I am missing something simple or else its not possible to do this. I have attached a simple code to demonstrate what I mean. The files are executed on a form submission.I have made two files and then a handler file to include the two files but still only outputs on pdf.
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Im a certificate');
$pdf->Output('Certificate.pdf', 'D'); //Output of the first invoice
$pdf = new FPDF(); // This is going to be the second pdf the Invoice
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Im an invoice');
$pdf->Output('This is a invoice.pdf', 'D');
//The problem is it only outputs the first one not this one
?>

PDF cretaion of webpage with fpdf return blank

I am trying to create direct pdf of webpage. so i am using fpdf for that.
I have kept fpdf files on fpdf folder and created a separate create-pdf.php file with following code :
<?php
require('fpdf.php');
$url = $_GET[$url1];
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,$url);
$pdf->Output();
?>
And used following php code to get current url of page of which pdf is to be created.
<?php
$url1 = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
?>
And Created a Link to create pdf as follows :
Create PDF
Now pdf is getting created in new tab...but It is Empty / blank...No text is there on created pdf...

codeigniter and fpdf code blockin during pdf output

i have a big problem with fpdf
in my page i have a lot of code and at the end i create a pdf file with this sample:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
ob_end_clean();
$pdf->Output();
the result is that only the creatioin of pdf are make and the other code no !
first the code of the sample is:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
//ob_end_clean();
$pdf->Output();
like this the code before is execute without problem but not the pdf and i receive this on browser:
FPDF error: Some data has already been output, can't send PDF file
can you help me ?
im newbie with fpdf libraries
that is because your php code has already outputted some data to the browser.
Check that your php do not write any data to the browser yet ( except for the headers ) before calling $pdf->Output(), thus avoiding sending unknown data that has a pdf binary data appended at the end.
the ob_end_clean() function call ensure that your script clean any previous output your php script could have made.

how to generate pdf and save to server

Well, i'm trying to generate pdf file and save it to server but when i'm trying to view that pdf its showing invalid format.
Code :
<?php
$content = "32w434";
file_put_contents("xyz.pdf",$content);
?>
If i change file from pdf to doc it works and opening perfectly but not pdf
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$content = $pdf->Output();
file_put_contents("xyz.pdf",$content);
That code giving output i don't want output on browser and still file is corrupted / invalid format
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$content = $pdf->Output('doc.pdf','F');
http://www.fpdf.org/
You can use FPDF to generate pdf file....
http://www.fpdf.org/
This is simple and best way to generate pdf...
Use TCPDF to generate PDF file,
TCPDF Site: http://www.tcpdf.org/
Demo: http://www.tcpdf.org/examples.php
#Mohit,
This
$content = $pdf->Output('doc.pdf','F');
generates a new file. If your file is generated using variables that can change in php, the pdf file you see on screen, will be different from the pdf file saved on the server.
You should generate pdf file using pdf libraries such as tcpdf or fpdf. Putting contents directly into a file with .pdf extension will definitely not working since pdf has its own file format

Categories