2017-07-11 5 views
0

以下のスクリプトは、GmailとOutlookへの添付ファイルとしてpdfファイルを送信できますが、Yahooメールには表示されません。私のコードに何が問題なのですか?PHPを使用して電子メール本文とPDF添付ファイルを送信するには?

第2に、メールを送信すると、pdf添付ファイル自体からメッセージ本文に沿って運ばれません。どのように私はPDF添付ファイルでメッセージの本文を追加することができます上の任意の提案は高く評価されます。

<?php 
include("inc/conn2.php"); 

$customer_ID=$_GET['id']; 
$invoice_ref_no=$_GET['ref']; 

$query_sql= "SELECT * FROM add_biller_setup"; 
$result = mysqli_query($conn,$query_sql); 
$row = $result->fetch_assoc(); 
$biller_email_address= $row['email_address']; 
$biller_email = str_replace(' ','',$biller_email_address); 


$customer_emails=$_POST['customer_emails']; 
//$cust_emails=explode(',', $customer_emails); 
foreach($customer_emails as $key => $email_value){ 

$to =$email_value; 
$subject = "Customer Invoice Details"; 

$pdfdoc = $mpdf->Output('', 'S'); 

$fileatttype = "application/pdf"; 
$fileattname = "Invoice.pdf"; 
$mainMessage = "Please find the attachment included the mail."; 


$headers .= 'From: ABS Motor LTD<[email protected]>' . "\r\n"; 
$headers .= 'Cc: '.$biller_email.'' . "\r\n"; 

$semi_rand  = md5(time()); 
$mime_boundary .= "==Multipart_Boundary_x{$semi_rand}x"; 
$headers  .= "MIME-Version: 1.0\n" . 
    "Content-Type: multipart/mixed;\n" . 
    " boundary={$mime_boundary}"; 

    //$headers = "MIME-Version: 1.0\n" ; 
    //$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n"; 
// $headers .= "X-Priority: 1 (Highest)\n"; 
    //$headers .= "X-MSMail-Priority: High\n"; 
    //$headers .= "Importance: High\n"; 

    $message = "This is a multi-part message in MIME format.\n\n" . 
    "-{$mime_boundary}\n" . 
    "Content-type:text/html;charset=UTF-8\n" . 
    "Content-Transfer-Encoding: 7bit\n\n" . 
    $mainMessage. "\n\n"; 

$data = chunk_split(base64_encode($pdfdoc)); 
$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 email 
if(mail($to,$subject,$message,$headers)){ 
    $customer_ID=$_GET['id']; 
    $invoice_ref_no=$_GET['ref']; 
    $successMsg = 'Invoice has sent successfully.'; 
    echo '<p style="color:green; font-weight:600; font-size:1.5em;">'.$successMsg.'</p>'; 
    echo '<p style="color:black; font-size:1.2em;">Shortly you will be re-directed back to the invoice page.</p>'; 
echo '<meta content="3;invoice_details?id='.$customer_ID.'&ref='.$invoice_ref_no.'" http-equiv="refresh" />'; 
} 
else{ 
    $customer_ID=$_GET['id']; 
    $invoice_ref_no=$_GET['ref']; 
    $errorMsg = 'Some problem occurred, please try again.'; 
    echo '<p style="color:red; font-weight:600; font-size:1.5em;">'.$errorMsg.'</p>'; 
    echo '<p style="color:black; font-size:1.2em;">Shortly you will be re-directed back to the invoice page.</p>'; 
    echo '<meta content="3;invoice_details?id='.$customer_ID.'&ref='.$invoice_ref_no.'" http-equiv="refresh" />'; 
} 
} 
?> 
+1

私はあなたのためのMIMEのものを処理するライブラリを使用することをお勧めし - [phpmailerの](https://github.com/PHPMailer/PHPMailer)を参照 –

+0

を私が追加することができますどのような状況の下で、[お読みください私の質問に「緊急」または他の同様のフレーズを使用すると、より迅速な回答を得ることができますか?](// meta.stackoverflow.com/q/326569) - これはボランティアに対処する理想的な方法ではなく、答えを得ることに逆効果があります。これをあなたの質問に追加しないでください。 – halfer

+0

あなたの訂正をありがとう、私は今までそれを知らなかった.. – Koodie

答えて

関連する問題