php电子邮件发送代码而不是html

时间:2012-10-16 06:31:09

标签: php html

我收到的是这种形式的电子邮件:

"<span style="color:red;"> blablabla text goes here </span>"

而不是

"blablabla text goes here"

红色。任何类型的HTML都作为代码发送出来......关于如何解决这个问题的任何想法? 提前谢谢

if(isset($_REQUEST['Message']) && $_REQUEST['Message']!="")
    {
        $header="From: ".$_REQUEST['FromName']."<".$_REQUEST['FromEmail'].">\r\n" .
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=iso-8859-1" . "\r\n".
        "Content-Transfer-Encoding: 8bit\r\n\r\n";
        $to=explode(",",$_REQUEST['Recipients']);
        for($i=0;$i<count($to);$i++)
        {
            $x=explode("<",$to[$i]);
            $x=explode(" ",$x[0]);
            $firstname=$x[0];
            mail($to[$i],$_REQUEST['Subject'],str_replace("\$firstname",$firstname,$_REQUEST['Message']),$header);
            //
        } 

1 个答案:

答案 0 :(得分:1)

示例代码如下所示。

<? 
    //change this to your email. 
    $to = "m@maaking.com"; 
    $from = "m2@maaking.com"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
    $message = "<html> 
  <body bgcolor=\"#DCEEFC\"> 
    <center> 
        <b>Looool!!! I am reciving HTML email......</b> <br> 
        <font color=\"red\">Thanks Mohammed!</font> <br> 
    </center> 
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine 
  </body> 
</html>"; 
   //end of message 

    // To send the HTML mail we need to set the Content-type header. 
    $headers = "MIME-Version: 1.0rn"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
    $headers  .= "From: $from\r\n"; 
    //options to send to cc+bcc 
    //$headers .= "Cc: maa@p-i-s.com"; 
    //$headers .= "Bcc:email@maaking.com"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?>