2017-07-05 11 views
0

私はpdfを生成しており、添付ファイルとして電子メールで送信しました。PDFを生成して添付ファイルとして電子メールで送信しました(PDFは開かれません)

//pdf generated not given avobe code of how it comes 
$pdfdoc = $pdf->Output("confirmation-".$client_code.".pdf", "S"); 

$attachment = chunk_split(base64_encode($pdfdoc)); 

$to = $mail_to;  

$from  = "From: <[email protected]>"; 

$subject  = "Here is your attachment"; 

$mainMessage = "BUY/SALE CONFIRMATION"; 

$fileatt  = $attachment; 

$fileatttype = "application/pdf"; 

$fileattname = "confirmation-".$client_code.".pdf"; 

$headers = "From: $from"; 

$file = fopen($fileatt, 'rb'); 

$data = fread($file, filesize($fileatt)); 

fclose($file); 


$semi_rand  = md5(time()); 

$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"; 
//base_64 
//encoding used 
//to encode data 
$data = chunk_split(base64_encode($data)); 

//message 
//concat the 
//message 
$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 "EMAIL SENT SUCCESSFUL."; 
} 
else { 
    echo "There was an error sending the mail."; 

メッセージは、電子メールが成功送られたと私はあまりにも電子メールを得たが、私はメールで添付のPDFファイルを開くことができませんでした.... 問題に

After opening the PDF fileを確認してください示した: コードをご確認ください

答えて

1

「phpmailer」を使用できます。 ここからPHPMailerスクリプトをダウンロードしてください:http://github.com/PHPMailer/PHPMailer そしてそれをお楽しみください。

+0

その問題についてご提案ください... – RokiDGupta

関連する問題