PHP表单发送空白电子邮件

问题描述:

我已经创建了一个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(); 
} 
?> 

更新版本

+1

添加错误文件(S)的顶部报告您开' 2015-02-06 22:02:04

+2

删除'isset'并启用'error_reporting'。几乎没有任何一个表单字段具有'name ='。 – mario 2015-02-06 22:02:23

+0

关闭我的头顶,看起来是由于某种原因isset($ _ POST ['submit']正在评估为false。也许该按钮需要一个ID吗? – mrunion 2015-02-06 22:03:12

,而不是使用 “” “;” 为收集信息。 ?与开始 “$体”,以 更改行:

$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); 
+0

仍为空白。所有我收到的是字段名称不是值 – 2015-02-06 22:46:29

+0

检查功能“邮件”。 – EngineerCoder 2015-02-07 12:47:42