我已經創建了一個PHP的我的消息從網站發送到客戶的電子郵件。但是一旦電子郵件發送,我收到一封空白的電子郵件。我試過使用。$ _ post ['name']。調用該字段,我已經嘗試過.name。PHP表單發送空白電子郵件
我使用引導來構建表單。
<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 = "[email protected]";
$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();
}
?>
更新版本
添加錯誤文件(S)的頂部報告您開'
2015-02-06 22:02:04
刪除'isset'並啓用'error_reporting'。幾乎沒有任何一個表單字段具有'name ='。 – mario 2015-02-06 22:02:23
關閉我的頭頂,看起來是由於某種原因isset($ _ POST ['submit']正在評估爲false。也許該按鈕需要一個ID嗎? – mrunion 2015-02-06 22:03:12