如何在我的php联系表单文本区域添加空格

时间:2017-03-20 00:48:11

标签: php

我有一个工作的php联系表单,但是当它发送消息时,文本区域中没有空格。我是php的新手,所以我不确定是怎么回事。我试图搜索答案,但在这里没有看到任何东西。关于如何解决这个问题的任何想法?

    <?php
   $name = $_POST["name"];
   $email= $_POST["email"];
   $message = $_POST["message"];

   //error message
   $missingName = "<p>Please enter your name.</p>";
   $missingEmail ="<p>Please enter your email address.</p>";
   $invalidEmail = "<p>Please enter a valid email address.</p>";
   $missingMessage = "<p>Please enter a message.</p>";

   if($_POST["submit"]){
    if(!$name){
        $errors .= $missingName;
    }else{
        $name=filter_var($name, FILTER_SANITIZE_STRING);
    }

    if(!$email){
        $errors .= $missingEmail;
    }else{
        $email=filter_var($email, FILTER_SANITIZE_EMAIL);
        if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
            $errors.=$invalidEmail;
        }
    }

    if(!$message){
        $errors.= $missingMessage;
    }else{
        $message= filter_var($message, FILTER_SANITIZE_EMAIL);
    }
    if($errors){
        $resultMessage= '<div class= "alert alert-danger">' . $errors . '</div>';
    } else{
        $to= "name@example.com";
        $subject= "Inquiry";
        $message= 
        "<p>Name: $name</p>
        <p>Email: $email</p>
        <p>Message:</p>
        <p>$message</p>";
        $headers = "Content-type: text/html";

        if (mail($to, $subject, $message, $headers)){
            $resultMessage = '<div class="alert alert-success">Thanks for your interest. We will get back to you as soon as possible.</div>';
        }else{
            $resultMessage ='<div class="alert alert-warning">Unable to send Email. Please try again later.</div>';
        }
    }
   }
   ?>

/ thanks.php代码 / $ finalmessage =“姓名:

1 个答案:

答案 0 :(得分:0)

Sink

应该是:

$message= filter_var($message, FILTER_SANITIZE_EMAIL);