PHP表单未显示有关提交的完整信息

时间:2017-06-10 15:53:23

标签: php forms

我有一个非常简单的表单来自一个只有三个字段的模板 - 名字 - 电子邮件 - 电话。提交表单时有效。但是 - 如果在名称字段中你有两个单词,例如John Smith - 那么它仍然会提交但是然后第一个单词之后的所有内容都会被截断 - 所以对于这个例子,收到的邮件只显示" john"并且不显示"史密斯",它也不会显示电子邮件或电话价值。我在下面给出了我的代码示例..非常感谢任何帮助。

以下PHP代码

<?php 
$to = 'x@gmail.com, y@gmail.com' ; // Put in your email address here
$subject  = "Appointment Request"; // The default subject. Will appear by   default in all messages. Change this if you want.

// User info (DO NOT EDIT!)
$name = stripslashes($_REQUEST['name']); // sender's name
$email = stripslashes($_REQUEST['email']); // sender's email
$phone = stripslashes($_REQUEST['phone']); 

// The message you will receive in your mailbox
// Each parts are commented to help you understand what it does exaclty.
// YOU DON'T NEED TO EDIT IT BELOW BUT IF YOU DO, DO IT WITH CAUTION!
$msg  = "Name: ".$name."\r\n";  // add sender's name to the message
$msg .= "E-mail: ".$email."\r\n";  // add sender's email to the message
$msg .= "Phone: ".$phone."\r\n";  // add sender's email to the message
$msg .= "Subject: ".$subject."\r\n\n"; // add subject to the message (optional! It will be displayed in the header anyway)
$msg .= "---Message--- \r\n";
$msg .= "\r\n\n"; 

$mail = @mail($to, $subject, $msg, "From:".$email);  // This command sends the e-mail to the e-mail address contained in the $to variable

if($mail) {
echo 'Your message has been sent, we will be in touch shortly!';  //This is the message that will be shown when the message is successfully send

} else {
echo 'Message could not be sent!';   //This is the message that will be shown when an error occured: the message was not send
}

?>

HTML表格代码

<form role="form" onSubmit="return send_email();">

<div class="form-group">

<label for="exampleInputName">Name</label>
          <input type="text" class="form-control" id="app_name" placeholder="Name" required>
        </div>
        <div class="form-group">
          <label for="exampleInputEmail1">E-mail</label>
          <input type="text" class="form-control" id="app_email" placeholder="E-mail" required>
        </div>
        <div class="form-group">
          <label for="exampleInputPassword1">Phone</label>
          <input type="text" class="form-control" id="app_phone" placeholder="Phone">
        </div>
        <button type="submit" class="btn btn-block btn-orange btn-Submit" onclick="ga('send', 'event', 'formsubmit', 'lp form', 'LP form');">Book my Free Consultation</button>
        <small id="mail_msg"></small>
      </form>

send_email()实际上是在一个单独的JS文件夹中的JS文件中..我已粘贴下面的代码..

JS send_email

function send_email() {
var name=$("#app_name").val();
var email=$("#app_email").val();
var phone=$("#app_phone").val();
if(name=="")
{
$("#app_name").addClass("errors");
}
else
{
$("#app_name").removeClass("errors");
}
if(!validEmail(email))
{
$("#app_email").addClass("errors");
}
else
{
$("#app_email").removeClass("errors");
}
if(phone=="")
{
$("#app_phone").addClass("errors");
}
else
{
$("#app_phone").removeClass("errors");
}

if(name!="" && phone!="" && validEmail(email) )
{
$("#mail_msg").load("email.php?name="+name+"&email="+email+"&phone="+phone);
$("#app_name").val('');
$("#app_email").val('');
$("#app_phone").val('');
}   
return false;
}
function validEmail(e) {
var filter = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
return String(e).search (filter) != -1;
}

0 个答案:

没有答案