В моем текущем проекте мне нужно на лету создать PDF-файл, прикрепить его как почтовое вложение и отправить.Работает нормально, файл генерируют и отправляют на почту, которую я предоставил.Когда я отправляю его в учетную запись Microsoft Outlook или Windows Live, файл PDF прикреплен, но не удается открыть файл с помощью PDF, выдает сообщение об ошибке и говорит, что он поврежден.Но с Gmail и Yahoo все работает нормально.У кого-нибудь есть решение для этого.Ниже мой код
$dompdf = new DOMPDF();
$dompdf->load_html($message);
$dompdf->set_paper("a4", "landscape");
$dompdf->render();
// The next call will store the entire PDF as a string in $pdf
$pdf = $dompdf->output();
// You can now write $pdf to disk, store it in a database or stream it to the client.
file_put_contents("pdfs/invoice.pdf", $pdf);
$fileatt = "pdfs/invoice.pdf"; // Path to the file
$fileatt_type = "pdf"; // File Type
$fileatt_name = "invoice.pdf"; // Filename that will be used for the file as the attachment
$fp = fopen($fileatt, "rb");
$file = fread($fp, filesize($fileatt));
$file = chunk_split(base64_encode($file));
$num = md5(time());
$to = "mail@mail.com";
$subject = "Invoice";
$headers = "From: " . "Manager" . "<" . "mail@mail.com" . ">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
$headers .= "Message-ID: <" . gettimeofday() . " TheSystem@" . $_SERVER['SERVER_NAME'] . ">\r\n";
$headers .= "X-Mailer: PHP v" . phpversion() . "\r\n";
$headers .= "Content-Type:".$fileatt_type." ";
$headers .= "name=\"".$fileatt_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$fileatt_name."\"\r\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "".$message."\r\n";
$headers .= "--".$num."--";
if (mail($to, $subject, $message, $headers)) {
fclose($fp);
echo "Success";
//header("location: client.php?m=1");
} else {
echo "Error";
//header("location: client.php?m=0");
}
Надеюсь, что кто-то может помочь мне решить проблему.