这是我的HTML代码:
<form method="POST" action="thank_you.php" novalidate>
<div class="form-group">
<label for="name">Full Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
<div class="valid-feedback">Looks good</div>
<div class="invalid-feedback">Please enter your name</div>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="eg: email@email.com" required>
</div>
<div class="form-group">
<label for="url">Your Website</label>
<input type="text" class="form-control" id="url" name="url" placeholder="eg: www.website.com">
</div>
<h4>Project Details</h4>
<p>Please provide a brief description of your project, what your end goal is, and how I can help you achieve this goal.
Please, also specify what your budget is.</p>
<div class="form-group">
<label for="budget">Budget Amount</label>
<input type="text" class="form-control" id="budget" name="budget" placeholder="eg: $2,000" required>
</div>
<div class="form-group">
<label for="project">Project Description</label>
<textarea class="form-control" id="project" name="project" rows="5" required></textarea>
</div>
<div class="form-group">
<label for="completion">Desired Completion Date</label>
<select class="form-control" id="completion" name="completion" required>
<option>Please select</option>
<option>As soon as possible</option>
<option>1-3 weeks</option>
<option>1-3 months</option>
<option>4-6 months</option>
<option>To be determined</option>
</select>
</div>
<button type="submit" class="btn btn-primary" name="submit">SEND</button>
</form>
这是我的PHP:
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$to = "jb@jbwebsitesolutions.com";
$subject = "New Request";
$body = "Please see details below.";
mail($to, $subject, $body);
?>
发生的情况是,一旦提交了表单,则仅显示邮件(函数)中的所有内容,而不显示输入内容。所以有人可以告诉我我出了什么问题以及如何解决吗?
答案 0 :(得分:4)
当前您的代码不完整,您应该将提交数据包括到$ body
像这样:
<select>
选项标签还必须具有value属性
$body = "Please see details below.";
$body .= '\r\n Name :'.$name.'\r\n';
$body .= '\r\n Email :'.$email.'\r\n';
答案 1 :(得分:0)
例如,您必须将POST数据传递到$ body标签中:
$to = "jb@jbwebsitesolutions.com";
$subject = "New Request";
$body = "";
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$body = "Hello ". $name."," .'<br/>';
$body .= $email;
$body .= "Your bugdet is :" . $budget;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$body,$headers);