Php 创建并通过电子邮件发送PDF
我已经用DOMPDF创建了PDF文件,我想将创建的文件发送到电子邮件,我使用了此代码,它正在发送文件,但是一个空白文件没有打开,请告诉我哪里出了问题,PS:我不想更改我的PDF库Php 创建并通过电子邮件发送PDF,php,email,pdf,Php,Email,Pdf,我已经用DOMPDF创建了PDF文件,我想将创建的文件发送到电子邮件,我使用了此代码,它正在发送文件,但是一个空白文件没有打开,请告诉我哪里出了问题,PS:我不想更改我的PDF库 <?php require_once("dompdf_config.inc.php"); $html="<h1>sdfsdff</h1>"; $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->rende
<?php
require_once("dompdf_config.inc.php");
$html="<h1>sdfsdff</h1>";
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
$name = "Name goes here";
$email = "abcl@gmail.com";
$to = "$name <$email>";
$from = "John-Smith ";
$subject = "Here is your attachment";
$mainMessage = "Hi, here's the file.";
$fileatt = $output;
$fileatttype = "application/pdf";
$fileattname = "output.pdf";
$headers = "From: $from";
// File
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
// This attaches the file
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$mainMessage . "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
// Send the email
if(mail($to, $subject, $message, $headers)) {
echo "The email was sent.";
}
else {
echo "There was an error sending the mail.";
}
?>