Я использую html2pdf для создания pdf-файла, и я пошлю его по почте.Почтовое приложение pdf файл
1- Я создал файл PDF: отлично работает
2- я спас его: отлично работает.
3- Я приложил его для отправки почты, но он не работает: я получил письмо с прикрепленным pdf-кодом, но его невозможно открыть! (filesize < нормальный размер файла). И когда я повторно отправляю почту, работает отлично!
У вас есть предложения, пожалуйста?
Моего код 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