联系表单字段未通过

时间:2014-07-08 10:33:05

标签: php forms twitter-bootstrap post em

我正在处理一个简单的联系表单,但是当电子邮件通过字段时为空。表单发送正常,但它没有获得任何值。我的表单HTML看起来像这样。

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
  <input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">
  <input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">
  <input type="text" name="email" id="email" class="input-block-level" required="required" placeholder="Your email address">
  <textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>

PHP的一面如下

header('Content-type: application/json');
   $status = array(
    'type'=>'success',
    'message'=>'Email sent!'
);

$nameFirst = $_POST['namefirst'];
$nameLast = $_POST['namelast']; 
$email = $_POST['email']; 
$message = $_POST['message']; 
$subject = $message;

$email_from = $email;
$email_to = 'jdwman14@gmail.com';

$body = 'Name: ' . $nameFirst .' '. $nameLast. "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;

$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

echo json_encode($status);

die;

当电子邮件通过时,它具有此格式但没有任何变量。

名称:

电子邮件:

主题:

消息:

提前致谢。

1 个答案:

答案 0 :(得分:0)

表格中有问题, 表单中有两个时间名称第一个输入字段

  <input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">

将namefirst替换为name&amp;中的lastname第二个输入中的id属性值如下,

<input type="text" name="namelast" id="namelast" class="input-block-level" required="required" placeholder="Your Last Name">

我希望这能解决你的问题...