表格回复未通过电子邮件发送

时间:2015-09-12 01:51:31

标签: php forms

我的表单没有通过电子邮件发送回复,我无法弄清楚原因。 ' $ __'中的所有内容似乎没有正确拉动。它在我的电子邮件中只是空白。这是一个多页的形式(2页),所以我想知道问题是什么,我错过了什么?

这是我的代码:

HTML:

<form name="firstForm" id="firstForm" action="submit.php" method="POST" enctype="">   

                       <div class="field"> <span class="fieldItem text">
                        <input autocomplete="off" placeholder="Address" id="address" name="address" type="text">
                        </span> </div>
                    </div>
                    <div class="col cols6 lastCol plm">
                      <div class="field"> <span class="fieldItem text">
                        <input name="unitnumber" id="unitnumber" placeholder="Unit #" type="text">
                        </span> </div>
                    </div>

                        <select style="width: 108px; position: absolute; opacity: 0; height: 36px; font-size: 14px;" id="state" name="state" class="styled sidebr01 hasCustomSelect">
                          <option selected="selected" value="-10">State</option>
                          <option value="AL">AL</option>
                         </select><span style="display: inline-block;" class="customSelect styled sidebr01"><span style="display: inline-block;" class="customSelectInner">State</span></span>
                        <div class="tobeSelectDisplay btn btnDefault"> <span class="selectLabel typeLowlight">State</span> <span class="selectTrigger typeLowlight"><i class="iconDownOpen"></i></span> </div>
                        </span> </span> </div>
                    </div>

                      <div class="field"> <span class="fieldItem text">
                        <input name="zip" placeholder="Zip" id="zip" type="text">


                  <a href="#" onClick="ValiDate();" class="mln typeDeemphasize btn btnPrimary btnLrg">Get a Personalized Report</a>
                  <noscript>

                  <div class="form_error hideFully box alert alertWarn mhs">
                    <div class="boxBody">
                      <p class="typeContrast mvm txtL"></p>
                    </div>
                  </div>
                  </noscript>


                               <label class="fieldLabel" for="ValuationInquiry[Full_Name]">Full Name</label>
                        <span class="fieldItem text">
                        <input placeholder="John Smith" name="full_name" id="full_name" type="text">
                        </span> </div>
                    </div>
                    <div class="col cols12 lastCol"></div>

        <div class="col cols12">
          <div class="field">
            <label class="fieldLabel" for="ValuationInquiry[Last_Name]">Last Name</label>
            <span class="fieldItem text">
              <input type="text" placeholder="Smith"  name="last_name" id="last_name">
            </span>
          </div>
        </div>
        <div class="col cols12 lastCol"></div>
      </div>-->
                  <div class="line pvm2">
                      <div class="field">
                        <label class="fieldLabel" for="ValuationInquiry[Email_Address]">Email Address</label>
                        <span class="fieldItem text">
                        <input placeholder="johnsmith@example.com" name="email_address" id="email_address" type="email">
                        </span> </div>
                    </div>
                    <div class="col cols12 lastCol"></div>
                  </div>
                  <div class="line ptm2">
                      <div class="field">
                        <label class="fieldLabel" for="ValuationInquiry[Phone]">Phone Number</label>
                        <span class="fieldItem text">
                        <input title="10-digit US Phone Number" name="phone" id="phone" type="text">
                        </span> </div>
                    <div class="col cols12 lastCol"></div>
                  </div>
                </div>

                    <input value="steptwo" name="skipsecondstep" type="hidden">
                    <input value="Get Your Full Report" id="required_form_cta" class="typeDeemphasize btn btnPrimary" onClick="lastvalidate();" type="button">


    <!--</form>--> 
  </div>
</form>

PHP:

<?php


$email_from = 'email@email.com';//<== update the email address
$email_subject = "Entry Received";
$email_body = "You have received a new message from the user $full_name.\n".
    "Zip Code:\n $zip".


$to = "email@email.com";//<== update the email address
$headers = "From: $email_address \r\n";
$headers .= "Reply-To: $email_address \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: submit.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}

?> 

1 个答案:

答案 0 :(得分:0)

您永远不会为$full_name$zip分配值。他们并没有神奇地填充表单中的值。 1 您必须自己分配这些值:

$full_name = $_POST['full_name'];
$zip = $_POST['zip'];
$email_body = "You have received a new message from the user $full_name.\n".
"Zip Code:\n $zip".

1 PHP曾经有一个名为register_globals的功能,默认情况下该功能自动填充表单中的变量。但是从PHP 5.3.0开始,这个功能已被弃用,并且从PHP 5.4.0开始被删除。