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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题