【问题标题】:php email sends code instead of html [closed]php电子邮件发送代码而不是html [关闭]
【发布时间】:2012-10-16 06:31:09
【问题描述】:

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

"<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);
            //
        } 

【问题讨论】:

  • 添加标题:'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  • 是的,这些都不起作用......我在问这里之前做了自己的研究......我发布了代码
  • 此代码允许从任何人向任何人发送电子邮件?这很好……也很危险! :)

标签: php html


【解决方案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....!"; 
?>

【讨论】:

  • 我发布了我的代码。我当然包括了标题
猜你喜欢
  • 1970-01-01
  • 2013-04-21
  • 2016-12-06
  • 1970-01-01
  • 2020-05-15
  • 2012-11-11
  • 2012-08-13
  • 1970-01-01
  • 2016-11-23
相关资源
最近更新 更多