我正在使用Bootstrap 4构建站点,并添加了一个表单。我把它放在我的服务器上并运行它,它起作用了!金田有4个字段,名字,姓氏,电子邮件,电话。验证有效,我将其发送到电子邮件,并且可以正常工作,但是无论在网站的输入字段中输入什么,电子邮件都会返回以下信息:
Name: S S.
Email: S.
Phone: S.
这是我的php:
<?php
$first_name= S_POST['first_name'];
$last_name= S_POST['last_name'];
$email= S_POST['email'];
$phone= S_POST['phone'];
$email_from =' Company, llc';
$email_subject = 'New Message From A Guest';
$email_body = "Name: $first_name $last_name.\n".
"Email: $email.\n".
"Phone: $phone.\n";
$to ="me@business.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("location: index.html");
?>
表单HTML:
<form class="form inline d-flex justify-content-center" action="contact.php" method="POST" role="form">
<br style="clear:both">
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="control" id="first_name" name="first_name" placeholder="First Name" required>
</div>
<div class="form-group">
<input type="text" class="control" id="email" name="email" placeholder="Email" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="control" id="last_name" name="last_name" placeholder="Last Name" required>
</div>
<div class="form-group">
<input type="text" class="control" id="phone" name="phone" placeholder="Phone" required>
</div>
</div>
<div class="col-sm-12">
<button type="submit" id="submit" name="submit" class="btn btn-primary">SEND</button>
</form>
是什么导致它只返回S作为这些输入的值?任何帮助将不胜感激
答案 0 :(得分:2)
$first_name= S_POST['first_name'];
$last_name= S_POST['last_name'];
$email= S_POST['email'];
$phone= S_POST['phone'];
不应为“ S_”,而应为美元$ _
例如:
$first_name= $_POST['first_name'];
$last_name= $_POST['last_name'];
$email= $_POST['email'];
$phone= $_POST['phone'];