PHP表单不允许断行

时间:2015-10-29 22:13:32

标签: php forms

<?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\r\nContent-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>";
        }
    }              
?>

我的联系页面上有这个表格,它有效,发送邮件。但问题在于它是如何显示的信息。我内心没有断线......看起来很奇怪。

鳕鱼怎么了?

1 个答案:

答案 0 :(得分:0)

在PHP文档中,您可以阅读有关应该编写消息的方式的有用说明。 这是:http://php.net/manual/en/function.mail.php

更具体地说 - 消息参数的说明。其中说:

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

注意

(仅限Windows)当PHP直接与SMTP服务器通信时,如果在行的开头找到句号,则会将其删除。要反作用,请用双点替换这些事件。

<?php
$text = str_replace("\n.", "\n..", $text);
?>