我的PHP表单是发送电子邮件而不是数据

时间:2014-01-02 21:36:09

标签: php

这是给我提出问题的代码部分,它是向我的地址发送电子邮件,但不是从网站上的表格中填写的数据:

        $emailSubject = 'Website Enquiry';
    $webMaster = 'cynthiab1984@gmail.com';

/*Gathering Data Variables*/

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $commentField = $_POST['comment'];

    $body = <<<EOD
<br><hr><br>
name: $name<br>
email: $email<br>
phone number: $phone<br>
comment: $comment<br>

EOD;
    $headers = "From:$email\r\n";
    $headers .= "Content-type:text/html\r\n";
    $success = mail ($webMaster, $emailSubject, $body, $headers);

3 个答案:

答案 0 :(得分:9)

您的字段被称为$nameField等,您将它们作为$name

放入电子邮件正文中

答案 1 :(得分:0)

检查字段名称,您会发现问题。 字段应为:

$nameField 
  $emailField
  $phoneField 
 $commentField

$name
$email
$phone
$comment

答案 2 :(得分:0)

// Edits made below
// This is your area to edit

$body = <<<EOD
    <br><hr><br>
    name: $nameField<br>
    email: $emailField<br>
    phone number: $phoneField<br>
    comment: $commentField<br>