douluhaikao93943 2013-11-14 12:35
浏览 148
已采纳

格式化电子邮件中的文本

Sorry, still a novice but getting better. I'm building a website and because I'm not that good I'm providing a page where club members can report problems and give me enough information to look into it. I have written the PHP code to send me an e-mail. If I echo the $message it prints fine on the screen but in an e-mail it's just one long sentence with the HTML tags in it. I searched for a solution and tried the ""Content-type: text/plain; charset=UTF-8"" but that did nothing. I know I'll be embarrassed when I get the answer but I am stuck. Thanks in advance.

<?php  
//  Convert form data to srting data

    $first_name=$_POST['first_name'];
    $last_name=$_POST['last_name'];
    $e_mail=$_POST['e_mail'];
    $browser=$_POST['browser'];
    $browser_version=$_POST['browser_version'];
    $os=$_POST['os'];
    $os_ver=$_POST['os_ver'];
    $device=$_POST['device'];
    $make=$_POST['make'];
    $issue=$_POST['issue'];

//  Use string data to create and send e-mail

    $to = '*******@*****.com';  //  will need to be converted to webmaster@stjoesclub.com
    $subject = 'Problem with St. Joseph Web Site';
    $message = $first_name . " " . $last_name . " is reporting a problem with the web site. <br><br>" .
               "E-mail address:  " . $e_mail . "<br><br>" .
               "Browser:  " . $browser . "<br>" .
               "Browser Version:  " . $browser_version . "<br><br>" .
               "Operating System:  " . $os . "<br>" .
               "Operating System Version:  " . $os_ver . "<br><br>" .
               "Device:       " . $device . "<br>" .
               "Device Make:   " . $make . "<br><br>" .
               $issue;


//  Send e-mail to webmaster

    mail($to, $subject, $message, 'From: ' . $e_mail, "Content-type: text/plain; charset=UTF-8");

?>
  • 写回答

3条回答 默认 最新

  • donglie1898 2013-11-14 13:40
    关注

    use Content-Type as text/html as below

    $eol="
    ";
    
    # Common Headers
    $headers = "Message-ID: <".time()."-".$e_mail.">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion().$eol;                      
    // These two to help avoid spam-filters
    
    # Boundry for marking the split & Multitype Headers
    $headers .= 'MIME-Version: 1.0'.$eol;
    $headers .= "Content-Type: text/html; charset=iso-8859-1".$eol.$eol;
    
    mail($to, $subject, $message, 'From: ' . $e_mail, $headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测