dousi6087 2016-01-02 22:24
浏览 362
已采纳

当有换行符时,CRLF( )会在电子邮件中显示

I'm not sure what I am doing wrong here. In the emails, keeps showing every time there is a line break. How can I modify the code to fix it?

public function sendSupportEmail($email, $name, $comments)
{
    // Wait until Google Apps are configured to accept from this domain
    //$to = "test@mail.com";
    $to = "test@mail.com.com";
    $subject = "Support: Support Inquiry";

    // Headers
    // To send HTML mail, you can set the Content-type header.
    $autoHeaders  = "MIME-Version: 1.0
";
    $autoHeaders .= "Content-type: text/html; charset=iso-88591
";
    $autoHeaders .= "From: Web Bot";
    $autoHeaders .= "<webbot@mail.com>
";
    $autoHeaders .= "Reply-To: webbot@mail.com
";
    $autoHeaders .= "Return-Path: webbot@mail.com
";
    $autoHeaders .= "X-Mailer: PHP 5.x
";

    // Print the local date
    $date = new DateTime('now', new DateTimeZone('America/Denver'));
    $datePrint = $date->format('F j, Y, g:i a');

    // Create Text Based Message Below
    $message = "<h3>Support Inquiry sent on {$datePrint}</h3>";
    $message .= "<b>Name:</b><br>{$name}<br><br>";
    $message .= "<b>Email:</b><br><a href='mailto:{$email}'>{$name}</a><br><br>";
    $message .= "<b>Comments:</b><p>{$comments}</p>";

    // Send them the E-Mail
    return mail($to, $subject, $message, $autoHeaders);
}
  • 写回答

2条回答 默认 最新

  • douren4075 2016-01-02 23:07
    关注

    The ideal function to use here would be PHP's nl2br() function.

    and used against the textarea input (or other inputs/variables) wherever you are using it. This has been established in comments that that is what you are using for the comments form element.

    I.e.: and assuming that your form element is named "comments" and using a POST method for it, since we don't know what that is, or where $comments has been assigned as. That wasn't in your question, therefore I am submitting the following as a possible solution.

    $comments = $_POST['comments'];
    $comments = nl2br($comments);
    

    Or, all in one go:

    $comments = nl2br($_POST['comments']);
    
    • Modify respectively if needed.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog