2012-04-05 28 views
0

PHPでHTMLメールを送信しようとしていますが、そのままテキストとして来ます。すべての値はPHPから正しく生成され、電子メールのテキストだけです。ここでは、コードは次のようになります。PHPでHTML電子メールを送信

$to='[email protected]'; 
    $from = '[email protected]'; 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $headers = "From: $from \r\n"; 
    $subject = "Print Run: " . $run . " is ordered"; 
    $body ="<html> 
      <head> 
      </head> 
      <body> 
      <table> 
       <tr> 
        <th>Company</th> 
        <th>Quantity</th> 
        <th>Size</th> 
        <th>Date Added</th> 
        <th> 
        </th> 
       </tr>"; 
      for($i = 0; $i < $arraySize; $i++){  
       $body .= "<tr><td>" . $companyName[$i] . "</td><td>" . $quantity[$i] . "</td><td>" . $cardSize[$i] . "</td><td>" . $dateAdded[$i] . "</td></tr>"; 
      } 
      $body .= "<tr> 
         <td style=\"font-weight:bold; border-style:solid; border-top-width:1px;\">Totals</td> 
         <td style=\"font-weight:bold; border-style:solid; border-top-width:1px;\">" . $totals . "</td> 
         <td></td> 
         <td></td> 
         <td></td> 
         </tr> 
         </table> 
         </body> 
         </html>"; 

    mail($to,"Print Run: " . $run . " is ordered",$body,$headers); 
+0

あなたがチェックしましたあなたの電子メールクライアントの設定に起因するものではありませんか? – mishu

答えて

11

次の3つのラインの最後のヘッダを上書き:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = "From: $from \r\n"; 

は(ドットに注意)であるべき:それはだ場合

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: $from \r\n"; 
+9

+1イーグルアイ。 –

+0

本当にそれを発見するのは難しくありませんでした:) –

+0

私が見たもう一つのつまらないものは "\ r \ n"です。これは一部のシステムでは失敗し、PHP_EOLに置き換えてください。 –

関連する問題