drux41001 2015-10-29 22:13
浏览 26

PHP表单不允许断行

<?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST'){
        $fname = $_POST['fname']; 
        $lname = $_POST['lname']; 
        $phone = $_POST['phone']; 
        $email = $_POST['email']; 
        $mesaj = $_POST['message'];  


        $to = "email@me.r";
        $subject = "Email from Website ";
                     $body = 'Nume - '.$fname.' 
                             Prenume - '.$lname.'
                             Email - '.$email.' 
                             Telefon - '.$phone.'
                             Mesaj - '.$mesaj;
        $headers = "From Contact <$email>";
        $headers .= "MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8";
        if(mail($to, $subject, $body, $headers)){
            echo "
                <p class='succes'>Thank you for sending me a message!</p>
                <meta http-equiv='refresh' content='3; url=contact-me.php' />";
        } else  {
            echo "<p class='succes'>I am sorry, but there appears to be a problem with the form you submitted.</p>";
        }
    }              
?>

I got this form for my contact page, it works, send the message. But the prblem is how the message it is displayed. I got no break lines inside of.. looks very weird.

Whats wrong in the cod?

  • 写回答

1条回答 默认 最新

  • dongzhihong3940 2015-10-29 22:41
    关注

    In PHP Documentation you can read useful notes about the way message should be written. Here it is: http://php.net/manual/en/function.mail.php

    More specifically - the explanation of message parameter. Which says:

    Each line should be separated with a CRLF ( ). Lines should not be larger than 70 characters.

    Caution

    (Windows only) When PHP is talking to a SMTP server directly, if a full stop is found on the start of a line, it is removed. To counter-act this, replace these occurrences with a double dot.

    <?php
    $text = str_replace("
    .", "
    ..", $text);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题