Jump to content

need a little help with 2 forms on one page, multiple email


jpolk
 Share

Recommended Posts

Hello,

 

Im a bit lost with this project, I cant seem to find the problem and I sure could use an extra set of eyes to look it over.

 

when the form is submitted it comes back to the error page and the emails are not sent. any ideas?

 

Thanks in advance!

<?phpfunction ValidateEmail($email){   $pattern = '/^([0-9a-z]([-.w]*[0-9a-z])*@(([0-9a-z])+([-w]*[0-9a-z])*.)+[a-z]{2,6})$/i';   return preg_match($pattern, $email);}if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'form344'){   $mailto = $_POST['unit'];if(isset($_POST['unit'])) {    $units['M17'][] = 'email@email.com, email@email.com';    $units['M16'][] = 'email@email.com';    $to       =  implode(",",$units[$_POST['unit']]);   $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;   $subject = 'Transfer';   $message = '';   $success_url = './success.php';   $error_url = './error.php';   $error = '';   $eol = "n";   $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;   $boundary = md5(uniqid(time()));   $header  = 'From: '.$mailfrom.$eol;   $header .= 'Reply-To: '.$mailfrom.$eol;   $header .= 'MIME-Version: 1.0'.$eol;   $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;   $header .= 'X-Mailer: PHP v'.phpversion().$eol;   if (!ValidateEmail($mailfrom))   {      $error .= "The specified email address is invalid!n<br>";   }   if (!empty($error))   {      $errorcode = file_get_contents($error_url);      $replace = "##error##";      $errorcode = str_replace($replace, $error, $errorcode);      echo $errorcode;      exit;   }   $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field");   $message .= $eol;   foreach ($_POST as $key => $value)   {      if (!in_array(strtolower($key), $internalfields))      {         if (!is_array($value))         {            $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;         }         else         {            $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;         }      }   }   $body  = 'This is a multi-part message in MIME format.'.$eol.$eol;   $body .= '--'.$boundary.$eol;   $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;   $body .= 'Content-Transfer-Encoding: 8bit'.$eol;   $body .= $eol.stripslashes($message).$eol;   if (!empty($_FILES))   {       foreach ($_FILES as $key => $value)       {          if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)          {             $body .= '--'.$boundary.$eol;             $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;             $body .= 'Content-Transfer-Encoding: base64'.$eol;             $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;             $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;          }      }   }   $body .= '--'.$boundary.'--'.$eol;   if ($mailto != '')   {      mail($mailto, $subject, $body, $header);   }mail($mailto, $subject, $body, $header);   header('Location: '.$success_url);   exit;}}if (session_id() == ""){   session_start();}if (!isset($_SESSION['username'])){   header('Location: ./notloggedin.php');   exit;}if (isset($_SESSION['expires_by'])){   $expires_by = intval($_SESSION['expires_by']);   if (time() < $expires_by)   {      $_SESSION['expires_by'] = time() + intval($_SESSION['expires_timeout']);   }   else   {      unset($_SESSION['username']);      unset($_SESSION['expires_by']);      unset($_SESSION['expires_timeout']);      header('Location: ./notloggedin.php');      exit;   }}if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'form1'){  $mailto = $_POST['unit'];if(isset($_POST['unit'])) {    $units['M17'][] = 'email@email.com, email@email.com';    $units['M16'][] = 'email@email.com';    $to       =  implode(",",$units[$_POST['unit']]);   $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;   $subject = '911';   $message = '';   $success_url = './success.php';   $error_url = './error.php';   $error = '';   $eol = "n";   $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;   $boundary = md5(uniqid(time()));   $header  = 'From: '.$mailfrom.$eol;   $header .= 'Reply-To: '.$mailfrom.$eol;   $header .= 'MIME-Version: 1.0'.$eol;   $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;   $header .= 'X-Mailer: PHP v'.phpversion().$eol;   if (!ValidateEmail($mailfrom))   {      $error .= "The specified email address is invalid!n<br>";   }   if (!empty($error))   {      $errorcode = file_get_contents($error_url);      $replace = "##error##";      $errorcode = str_replace($replace, $error, $errorcode);      echo $errorcode;      exit;   }   $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field");   $message .= $eol;   foreach ($_POST as $key => $value)   {      if (!in_array(strtolower($key), $internalfields))      {         if (!is_array($value))         {            $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;         }         else         {            $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;         }      }   }   $body  = 'This is a multi-part message in MIME format.'.$eol.$eol;   $body .= '--'.$boundary.$eol;   $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;   $body .= 'Content-Transfer-Encoding: 8bit'.$eol;   $body .= $eol.stripslashes($message).$eol;   if (!empty($_FILES))   {       foreach ($_FILES as $key => $value)       {          if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)          {             $body .= '--'.$boundary.$eol;             $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;             $body .= 'Content-Transfer-Encoding: base64'.$eol;             $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;             $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;          }      }   }   $body .= '--'.$boundary.'--'.$eol;}}?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...