php
  • html
  • email
  • 2012-04-05 121 views 0 likes 
    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 2012-04-05 15:21:16

    回答

    11

    您覆盖在最后三个行头:

    $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鹰眼。 – 2012-04-05 15:21:50

    +0

    是不是很难发现它,真的:) – 2012-04-05 15:23:57

    +0

    我见过的另一个gotcha是“\ r \ n”。这在某些系统上会失败,应该用PHP_EOL替换。 – 2012-04-05 15:24:11

    相关问题