douxu2467 2015-10-23 00:01
浏览 60

对电子邮件中的php表单提交空白字段进

I know this question has been asked before, I have researched but can't seem to get to the route of the problem. I'm hoping someone can help. Ok so form seems to be working in as much as the form has to be completed before it allows to be sent, the form sends and an email arrives. Unfortunately the email fields are blank.

So here's the php:

<?php

$Body  = 'MIME-Version: 1.0' . "
";
$Body .= 'Content-type: text/html; ch***t=utf-8' . "
";
$Body .= 'From: '. $EmailFrom . "
" . '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 .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";

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

// 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\">";
}
?>

My 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>

I appreciate it's probably me being really dense. I'm new to this so am fumbling my way around. Any help would be greatly appreciated. Many thanks!

  • 写回答

1条回答 默认 最新

  • duanniesui6391 2015-10-23 00:20
    关注

    The $_POST keys are CaSe SenSitIve

    $_POST['Name'] is different from $_POST['name']

    Either change the form name attribute or the POST keys so they match, i.e.:

    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'])); 
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据