对电子邮件中的php表单submition空白字段进行故障诊断

时间:2015-10-23 00:01:44

标签: php forms email

我知道之前已经问过这个问题,我已经研究过但似乎无法找到问题的路线。我希望有人可以提供帮助。好的,所以表单似乎正在工作,因为表单必须在允许发送,表单发送和电子邮件到达之前完成。不幸的是,电子邮件字段是空白的。

所以这是php:

<?php

$Body  = 'MIME-Version: 1.0' . "\r\n";
$Body .= 'Content-type: text/html; ch***t=utf-8' . "\r\n";
$Body .= 'From: '. $EmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion();

$EmailFrom = "info@mywebsite.com";
$EmailTo = "info@mywebsite.com";
$Subject = "Contact Form";
$Name = trim(stripslashes($_POST['Name'])); 
$Email = trim(stripslashes($_POST['Email'])); 
$Message = trim(stripslashes($_POST['Message'])); 
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("Location: http://mywebsite.com/formredirect.html");
exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom" . "\r\n");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"1;URL=formredirect.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"1;URL=error.html\">";
}
?>

我的HTML:

<form method="post" action="contact.php" name="contact" id="contact">
                                        <div class="row 50%">
                                            <div class="6u 12u(mobile)">
                                                <input type="text" name="name" id="name" placeholder="Name" required />
                                            </div>
                                            <div class="6u 12u(mobile)">
                                                <input type="text" name="email" id="email" placeholder="Email" required />
                                            </div>
                                        </div>

                                        <div class="row 50%">
                                            <div class="12u">
                                                <textarea name="message" id="message" placeholder="Message" required></textarea>
                                            </div>
                                        </div>
                                        <div class="row 50%">
                                            <div class="12u">
                                                <input type="submit" class="button" id="submit" value="submit"></a>

                                            </div>
                                        </div>
                                    </form>

我很欣赏它可能是我非常密集。我是新手,所以我正在摸索着。任何帮助将不胜感激。非常感谢!

1 个答案:

答案 0 :(得分:0)

$_POST键是 CaSe SenSitIve

$_POST['Name']$_POST['name']

不同

更改表单name属性或POST keys以使它们匹配,即:

<强> FORM

<input type="text" name="name" id="name" placeholder="Name" required />
...
<input type="text" name="email" id="email" placeholder="Email" required />
...
<textarea name="message" id="message" placeholder="Message" required></textarea>
...

<强> PHP

...
$Name = trim(stripslashes($_POST['name'])); 
$Email = trim(stripslashes($_POST['email'])); 
$Message = trim(stripslashes($_POST['message'])); 
...