我为我的消息创建了一个php,从网站发送到客户端电子邮件。但是一旦发送电子邮件,我会收到一封空白电子邮件。我尝试过使用。$ _ post ['name']。打电话给我,我试过.name。
我正在使用bootstrap构建表单。
<form class="email" method="post" action="mailer.php">
<div class="form-group col-md-6">
<label for="name">Full Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Your Full Name">
</div>
<div class="form-group col-md-6">
<label for="telephone">Telephone</label>
<input type="text" class="form-control" id="telephone" name="telephone" placeholder="Enter Your Telephone Number">
</div>
<div class="form-group col-md-6">
<label for="postcode">Post Code</label>
<input type="text" class="form-control" id="postcode" name="postcode" placeholder="Postcode">
</div>
<div class="form-group col-md-6">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter Your Email">
</div>
<div class="form-group col-md-6">
<label for="laptopmake">Make</label>
<input type="text" class="form-control" id="laptopmake" name="laptopmake" placeholder="Enter Your Laptop Make(HP,Toshiba">
</div>
<div class="form-group col-md-6">
<label for="laptopmodel">Model</label>
<input type="text" class="form-control" id="laptopmodel" name="laptopmodel" placeholder="Enter Your Laptop Model Number">
</div>
<div class="form-group col-md-12">
<label for="faultdescription">Fault Description</label>
<textarea class="form-control" rows="4" id="faultdescription" name="faultdescription" placeholder="Describe Your Laptop Fault"></textarea>
</div>
<div class="form-group col-md-6">
<button type="submit" class="btn btn-warning">
Send Message
</button>
</div>
</form>
这是PHP邮件程序。
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
print_r($_POST)
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$postcode = $_POST['postcode'];
$laptopmake = $_POST['laptopmake'];
$laptopmodel = $_POST['laptopmodel'];
$faultdescription = $_POST ['faultdescription'];
$message =$_POST['message'];
$to = "aihsanm93@gmail.com";
$subject="Laptop Repair Request!";
$body = 'Name:' .$name. "\n\n"; 'Email:' .$email. "\n\n" ;'Postcode:' .$postcode. "\n\n"; 'Message:' .$message . "\n\n";'Telephone:' .$telephone. "\n\n"; 'Laptop Make:' .$laptopmake. "\n\n"; 'Laptop Model:' .$laptopmodel. "\n\n"; 'Fault Description:' .$faultdescription. "\n\n"; mail($to, $subject,$body, $from);
echo "Your Message has been sent";
header('Location: index.html');
exit();
/* Functions we used */
function check_input($data, $problem=''){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
};
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
更新版本
答案 0 :(得分:0)
使用&#34; 。 &#34;而不是&#34; ; &#34;收集信息。 更改行开头&#34; $ body&#34;致:
$body = 'Name:' .$name. "\n\n" . 'Email:' .$email. "\n\n" . 'Postcode:' .$postcode. "\n\n". 'Message:' .$message . "\n\n" . 'Telephone:' .$telephone. "\n\n" . 'Laptop Make:' .$laptopmake. "\n\n" . 'Laptop Model:' .$laptopmodel. "\n\n" . 'Fault Description:' .$faultdescription. "\n\n";
mail($to, $subject,$body, $email);