2014-01-21 2 views
0

Я использую 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); 
+0

Это помогло бы много, чтобы увидеть код, который вы используете. – mbarthelemy

+0

Мой код php выше, я не могу добавить его в комментарий (длинный текст) :) – Nashen

+0

на той же странице php page1.php, у меня есть ссылка на page2.php (я могу сгенерировать и сохранить PDF) и в page2.php у меня есть действие, чтобы вернуться на page1.php и отправить почту ... – Nashen

ответ

0

(испытано и крепление полученного на SINGLE перспективы)

Вы были некоторые одиночные кавычки, которые должны были быть двойными кавычками и не закрывать текст тела полуколонии.

$message .= 'Bonjour, Veuillez trouver ci-joint la facture correspondant à votre abonnement sur mondmain.fr.' 

Был изменен: (с закрытием запятой)

$message .= "Bonjour, Veuillez trouver ci-joint la facture correspondant à votre abonnement sur mondmain.fr"; 

Если то, что я писал ниже не работает, попробуйте заменить эту строку:

$attachment = @chunk_split(base64_encode(file_get_contents($path))); 

с:

$attachment = @chunk_split(base64_encode(file_get_contents($filename))); 

Это то, что я использовал чтобы проверить его, поскольку у меня нет такой же настройки, как вы, используя переменную $id.

Rewrite: (Успешно протестирована с одним из моих 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"; 
$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); 
?> 
+0

Да, но не работает, файлize pdf attach = 50k! невозможно открыть файл – Nashen

+0

Что вы подразумеваете под '50k'? 50 мегабайт? @Nashen –

+0

Если это то, что вы имели в виду под 50 КБ (50 МБ), ваш сервер может ограничивать размер файла и может быть связан с настройкой максимальной загрузки. Прочтите это в отношении прикрепленных файлов: http://en.wikipedia.org/wiki/Email_attachment @Nashen --- И вы можете прочитать это, где у кого-то была аналогичная проблема http://www.roundcubeforum.net/index.php ? тема = 2398.0 –

Смежные вопросы