我使用html2pdf生成PDF文件,我會通過郵件附件發送它。郵件附件pdf文件
1 - 我已經創建了一個PDF文件:正常工作
2 - 我已經保存它:正常工作。
3我附上它發送郵件,但它不起作用:我收到一封附帶pdf的郵件,但無法打開它! (文件大小<正常文件大小)。當我再次發送郵件時,工作正常!
你有什麼建議嗎?
我的PHP代碼:
$filename='facture.pdf';
$mail_to = $email;
$subject = "Facture";
$random_hash = md5(time());
$headers = "From:" .$mailnotif." \r\nReply-To: mondmain.fr";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$path = 'http://mondmain.fr/Factures/'.$id.'/'.$filename.'';
$attachment = @chunk_split(base64_encode(file_get_contents($path)));
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the plain text message.
$message .= strip_tags($subject);
$message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
."Content-Type: text/html; charset=\"utf-8\"\r\n" ."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= 'Bonjour,
Veuillez trouver ci-joint la facture correspondant à votre abonnement sur mondmain.fr.'
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"
."Content-Type: application/doc; name=\"$filename\"\r\n"
."Content-Type: application/pdf; name=\"$filename\"\r\n"
."Content-Type: application/docx; name=\"$filename\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
//send the email
mail($mail_to, $subject , $message, $headers);
這將有很大的幫助,看你使用的代碼。 – mbarthelemy
我的代碼php是以上,我不能將它添加在評論(長文本:) :) – Nashen
在同一頁面php page1.php,我有一個鏈接到page2.php(我可以生成和保存pdf)和在page2.php我有一個行動返回page1.php和發送郵件... – Nashen