2011-10-27 10 views
0

첨부 파일이있는 이메일을 보내는 코드가 있습니다. 첨부 파일이있는 전자 메일은 받았지만 html 요소가 표시됩니다. 나는 Content-Type을 사용하고있다 : multipart/mixed; boundary = ... 첨부 파일이있는 전자 메일을 보내면 전자 메일의 html 요소가 표시되지만 첨부 파일을 보내지 않으면 전자 메일이 제대로 표시됩니다.PHP로 html 이메일 보내기

if(is_uploaded_file($_FILES['attachment']['tmp_name'])){ 
      //die("uploaded"); 
      copy($_FILES['attachment']['tmp_name'],"attachments/" . $_FILES['attachment']['name']); 
      $file = $_FILES['attachment']['tmp_name']; 
      $file_type = $_FILES['attachment']['type']; 
      $file_name = $_FILES['attachment']['name']; 
      $fopen = fopen($file, 'rb'); 
      $data = fread($fopen,filesize($file)); 
      fclose($fopen); 

      $semi_rand = md5(time()); 
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

      $headers = "From: " .EMAIL_FROM_ADDR. "\r\n"; 
      $headers .= "Reply-To: ".EMAIL_FROM_ADDR."\r\n"; 
      $headers .= "CC: [email protected]\r\n";  
      $headers .= "MIME-Version: 1.0\r\n"; 
      $headers .= "Content-Type: multipart/mixed; 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". 
         "<table border='1' cellspacing='1' cellpadding='1'>". 
         "<tr><td>Vendor Name:</td><td>".$_POST['vendor_name']."</td></tr>". 
         "<tr><td>Internet Agreement No:</td><td>".$_POST['internet_agreement_no']."</td></tr>". 
         "<tr><td>Vendor Duns No:</td><td>".$_POST['vendor_duns_no']."</td></tr>". 
         "<tr><td>Fee to NEXCOM:</td><td>".$_POST['fee_to_nexcom']."%</td></tr>". 
         "<tr><td>Settlement Worksheet For:</td><td>".$_POST['settlement_worksheet_date']."</td></tr>". 
         "<tr><td colspan='2'>&nbsp;</td></tr>". 
         "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_1']."</td></tr>". 
         "<tr><td>Deductions:</td><td>$".$_POST['deductions']."</td></tr>". 
         "<tr><td>Refunds/Credits(Attach Backup):</td><td>$".$_POST['refunds_credits']."</td></tr>". 
         "<tr><td>Sales Tax:</td><td>$".$_POST['sales_tax']."</td></tr>". 
         "<tr><td>State Tax:</td><td>$".$_POST['state_tax']."</td></tr>". 
         "<tr><td>Other(Explain):".$_POST['explain_1']."</td><td>$".$_POST['other_1']."</td></tr>". 
         "<tr><td>Other(Explain):".$_POST['explain_2']."</td><td>$".$_POST['other_2']."</td></tr>". 
         "<tr><td>Total Deductions:</td><td>$".$_POST['total_deductions']."</td></tr>". 
         "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_2']."</td></tr>". 
         "<tr><td>Less Deductions:</td><td>$".$_POST['less_deductions']."</td></tr>". 
         "<tr><td>Net Sales Subject to Commission:</td><td>$".$_POST['net_sales_subject']."</td></tr>". 
         "<tr><td>Net Commission due to NEXCOM:</td><td>$".$_POST['net_commission_due']."</td></tr>". 
         "<tr><td colspan='2'>Comments:</td></tr>". 
         "<tr><td colspan='2'>".$_POST['comments']."</td></tr>". 
         "</table>\n\n"; 

      $data = chunk_split(base64_encode($data)); 
      $message .= "--{$mime_boundary}\n". 
         "Content-Type: {$file_type}; name=\"{$file_name}\"\n". 
         "Content-Disposition: attachment; filename=\"{$file_name}\"\n". 
         "Content-Transfer-Encoding: base64\n\n". 
         $data."\n\n". 
         "--{$mime_boundary}--\n";  
     } 
     else{ 
      //die("not uploaded"); 
      $headers = "From: " .EMAIL_FROM_ADDR. "\r\n"; 
      $headers .= "Reply-To: ".EMAIL_FROM_ADDR."\r\n"; 
      $headers .= "CC: [email protected]\r\n"; 
      $headers .= "MIME-Version: 1.0\r\n"; 
      $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
      $message = "<table border='1' cellspacing='1' cellpadding='1'>". 
         "<tr><td>Vendor Name:</td><td>".$_POST['vendor_name']."</td></tr>". 
         "<tr><td>Internet Agreement No:</td><td>".$_POST['internet_agreement_no']."</td></tr>". 
         "<tr><td>Vendor Duns No:</td><td>".$_POST['vendor_duns_no']."</td></tr>". 
         "<tr><td>Fee to NEXCOM:</td><td>".$_POST['fee_to_nexcom']."%</td></tr>". 
         "<tr><td>Settlement Worksheet For:</td><td>".$_POST['settlement_worksheet_date']."</td></tr>". 
         "<tr><td colspan='2'>&nbsp;</td></tr>". 
         "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_1']."</td></tr>". 
         "<tr><td>Deductions:</td><td>$".$_POST['deductions']."</td></tr>". 
         "<tr><td>Refunds/Credits(Attach Backup):</td><td>$".$_POST['refunds_credits']."</td></tr>". 
         "<tr><td>Sales Tax:</td><td>$".$_POST['sales_tax']."</td></tr>". 
         "<tr><td>State Tax:</td><td>$".$_POST['state_tax']."</td></tr>". 
         "<tr><td>Other(Explain):".$_POST['explain_1']."</td><td>$".$_POST['other_1']."</td></tr>". 
         "<tr><td>Other(Explain):".$_POST['explain_2']."</td><td>$".$_POST['other_2']."</td></tr>". 
         "<tr><td>Total Deductions:</td><td>$".$_POST['total_deductions']."</td></tr>". 
         "<tr><td>Total Gross Sales:</td><td>$".$_POST['total_gross_sales_2']."</td></tr>". 
         "<tr><td>Less Deductions:</td><td>$".$_POST['less_deductions']."</td></tr>". 
         "<tr><td>Net Sales Subject to Commission:</td><td>$".$_POST['net_sales_subject']."</td></tr>". 
         "<tr><td>Net Commission due to NEXCOM:</td><td>$".$_POST['net_commission_due']."</td></tr>". 
         "<tr><td colspan='2'>Comments:</td></tr>". 
         "<tr><td colspan='2'>".$_POST['comments']."</td></tr>". 
         "</table>"; 
     }   

답변

1

당신은 당신의 메시지 본문에 Content-Type: text/plain;을 쓰고있어 : 다음은 코드입니다. 이것을 text/html으로 설정하면 트릭을 수행해야합니다.

0

라이브러리를 사용하여이 작업을 수행 할 수 있습니다. 그들은 잘 사용되며 다림질 된 많은 버그가 있으며, 그들은 무료입니다.

것들은 내가

http://swiftmailer.org/

http://phpmailer.worxware.com/

내 개인적인 취향 사용 후의 대부분이 SO

입니다 언급 한 두 swiftmailer

입니다 참조