2016-10-11 18 views
1

このコードでは、別のウィンドウから生成されたBase64 URI文字列としてPDFエンコードファイルを取得し、PHPセッション変数として宣言しています。電子メールを送信しますが、Base64は文字のトンとしてデコードされ、適切に添付されたものではありません。base64文字列をメール添付pdf

function MailWithAttachment($to, $subject, $message, $senderMail, $senderName, $files){ 

$from = $senderName." <".$senderMail.">"; 
$headers = "From: $from";$headers = "MIME-Version: 1.0$newline". 
     "Content-Type: application/pdf;". 
     "boundary = \"$boundary\"$newline$newline". 
     "--$boundary$newline". 
     "Content-Type: application/pdf; charset=ISO-8859-1$newline; Content-Disposition: attachment;". 
     "Content-Transfer-Encoding: base64$newline$newline"; 
echo "<script>alert('$files')</script>"; 
$headers .= rtrim(chunk_split($files)); 
$returnpath = "-f" . $senderMail; 
//send email 
$mail = @mail($to, $subject, $message, $headers, $returnpath); 
if($mail){ return TRUE; } else { return FALSE; } 
} 

答えて

2

最後に、私は以前に私のbase64でpdfファイルをデコードし、変数にデコードされた文字列を保存し、添付ファイルのatributeでその変数をsetted。

ところで、私は

<?php 
$_SESSION["sesDataPDF"] = $_POST["hdn_UriPdf"]; 
$b64file = $_SESSION["sesDataPDF"]; 
$decodPdf; 
if ($b64file){ 
    $nomPdf = ; 
    $nomPdf .= ".pdf"; 
    $nomPdf = (string)$nomPdf; 
    $b64file= trim(str_replace('data:application/pdf;base64,', "", $b64file)); 
    $b64file= str_replace(' ', '+', $b64file); 
    $decodPdf= base64_decode($b64file); 
    file_put_contents($nomPdf, $decodPdf); 
    $mail = new PHPMailer; 
    $mail->isSendmail(); 
    $mail->setFrom('', ''); 
    $mail->addAddress($mail, $name); 
    //Set the subject line 
    $mail->Subject = ''; 
    $mail->Body = ''; 
    $mail->AltBody = ''; 
    $mail->addAttachment($nomPdf); 
    $mail->Timeout=60; 
} 
?> 
PHPメーラーを使用しました
関連する問題