i'm used fpdf for create pdf with php. everything are ok. but i want to send pdf file to outlook.
I'm using $pdf->Output('file.pdf','D');
it's running. I want to attachment this file to microsoft outlook.
How i can this ?
i'm used fpdf for create pdf with php. everything are ok. but i want to send pdf file to outlook.
I'm using $pdf->Output('file.pdf','D');
it's running. I want to attachment this file to microsoft outlook.
How i can this ?
Something you can do is save the file to a temporary location on the server, and then use something like PHPMailer to attach that saved file to the email. PHPMailer is a lot easier to use for attachments than PHP's built-in mail
function.
You can temporarily store your PDF file a number of ways. Here's one:
$tempfilename = time().'.pdf';
$pdf->Output($tempfilename,'F');
Then in PHPMailer, you can attach it as such:
$mail->addAttachment($tempfilename);
And then after you are done, you can remove the temporary file from the server.
unlink($tempfilename);
If PHPMailer is not possible to use for your situation for whatever reason, you can use PHP's built-in mail
function. If you're working from a fresh file or a small file where the cost of adding PHPMailer is relatively small, do that if you can. Otherwise, you may try adding code like this to your $headers
. Adapted from an answer on using mail
to send attachments:
// Generate a random hash to send mixed content
$sep = md5(time());
// End of line
$eol = PHP_EOL;
// Content of file
$content = file_get_contents($tempfilename);
$content = chunk_split(base64_encode($content));
// Add attachment to headers
$headers .= "--" . $sep . $eol;
$headers .= "Content-Type: application/octet-stream; name=\"" . $tempfilename . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: base64" . $eol;
$headers .= "Content-Disposition: attachment" . $eol . $eol;
$headers .= $content . $eol . $eol;
$headers .= "--" . $sep . "--";