PHP form generating blank emails -


i've found lot of threads outlining similar issues this, code looked bit different , each solution vastly different, pretty green php world, appreciate here!

we have landing pages lead forms on them. of time work , there's system in place keep blank submissions, or submissions missing required fields, submitting. however, we've been getting strings of blank emails these forms-- in bursts of 2 @ same time, not always. not think pressing submit button without filling out fields because i've tested many times , nothing has ever come through. know enough php recognize i'm looking at, have little experience writing things scratch, , these forms made person held position before me, it's possible they're messed in fundamental way , didn't recognize because of limited php experience.

here's html form section of our page:

<form method="post" name="form-name" id="form-name" action="process.php">     <input type="hidden" id="pin" name="pin"/>           <input type="text" name="firstname" class="lettersonly" id="firstname"  placeholder="first name" value="" required />         <input type="text" name="lastname" class="lettersonly" id="lastname" placeholder="last name" value="" required />           <input type="email" name="email" class="email" id="email" placeholder="email" value="" required />          <input type="tel" name="phone" class="digits" id="phone" placeholder="phone" value="" required />          <input type="text" name="zipcode" class="digits" id="zipcode" placeholder="zip code" value="" required />      <?php echo $errorstring; ?>      <div id="submit_buttons">         <input type="submit" class="submit-form" />     </div>     </form> 

and here our entire process.php file:

<?php session_start();  $allowedfields = array(     'firstname',     'lastname',     'email',     'phone',     'zipcode', );  $requiredfields = array(     'firstname',     'lastname',     'email',     'phone',     'zipcode', );  $requiredemail = array(     'email', );  $errors = array(); foreach($_post $key => $value) {     // first need make sure allowed field     if(in_array($key, $allowedfields))     {         $$key = $value;          // required field?         if(in_array($key, $requiredfields) && $value == '')          {             $errors[] = "the field $key required.";         }          // required field?         if(in_array($key, $requiredemail) && !filter_var($value, filter_validate_email))             {             $errors[] = "a valid email required.";         }     }    }  // there errors? if(count($errors) > 0) {     $errorstring = '<div class="error2"><h1>there error form.</h1><br />';     $errorstring .= '<ul>';     foreach($errors $error)     {         $errorstring .= "<li>$error</li>";     }     $errorstring .= '</ul></div>';      // display previous form     include 'index.php'; } else {  if(isset($_post['firstname'])){ $firstname = $_post['firstname']; }  if(isset($_post['lastname'])){ $lastname = $_post['lastname']; }  if(isset($_post['email'])){ $email = $_post['email']; }  if(isset($_post['phone'])){ $phone = $_post['phone']; }  if(isset($_post['zipcode'])){ $zipcode = $_post['zipcode']; }   $formcontent = "$firstname $lastname \r\n$email \r\n$phone \r\n$zipcode \r\n";;      // toggle line on or off testing '//'   //$recipient = "<ben@plumdm.com>";      // change emails $recipient = "web dev <developer@site.com>";      // change subject line number $subject = "getmyreport.org/001 - landing page lead";  $mailheader = "landing page <landings@plumdm.com>"; mail($recipient, $subject, $formcontent, $mailheader) or die("error!");      // change url number header("location: http://www.getmyreport.org/thanks.html"); } 

i did make change in based on i've read here in other similar threads, doesn't seem have worked. changed original code:

$_post['firstname'])){ $name = $_post['firstname']; 

to this, in current code above:

if(isset($_post['firstname'])){ $name = $_post['firstname']; }  

it worked poster of other similar post, i'm still getting blank emails.

i noticed in error_log file, there entries corresponding arrival of blank emails this:

[04-apr-2014 10:49:22 america/denver] php notice:  undefined variable: firstname in /home3/plumdmco/public_html/getmyreport/001/process.php on line 69 [04-apr-2014 10:49:22 america/denver] php notice:  undefined variable: lastname in /home3/plumdmco/public_html/getmyreport/001/process.php on line 69 [04-apr-2014 10:49:22 america/denver] php notice:  undefined variable: email in /home3/plumdmco/public_html/getmyreport/001/process.php on line 69 [04-apr-2014 10:49:22 america/denver] php notice:  undefined variable: phone in /home3/plumdmco/public_html/getmyreport/001/process.php on line 69 [04-apr-2014 10:49:22 america/denver] php notice:  undefined variable: zipcode in /home3/plumdmco/public_html/getmyreport/001/process.php on line 69 

i'm stumped on 1 , hours of research hasn't gotten me anywhere. i'd appreciate if can offer it! thanks!

edit - lot of mentioning mismatched variables-- mistake, copied in-progress file had saved instead of active one. fixed now. sorry!

i believe what's happening users going directly process.php somehow. trigger email though post array empty, , produce empty email. since post array empty, undefined variable notices. avoid this, can wrap of code in process.php in if block.

if accesses page directly, server request method get. instead of sending email, redirect users form page.

if ($_server["request_method"] == "post"){      $allowedfields = array(         'firstname',         'lastname',         'email',         'phone',         'zipcode',     );      //same, same, same, way down      // change url number     header("location: http://www.getmyreport.org/thanks.html");     }  } else {      header("location: index.php");  } 

also, line has 2 semicolons:

$formcontent = "$firstname $lastname \r\n$email \r\n$phone \r\n$zipcode \r\n";;  //;; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -