Jump to content

Simple Form Post / Email issue


ilottl

Recommended Posts

I have the simple code below which seems to have worked on forms from a contact page on a website.

 

Unfortunately, it seems to only send the forms if all fields are entered. I have played with the code but cannot seem to get it to send any field that has been completed on submit.

 

Can someone help please?

 

<?php

 

$emailAddress = "bigL@gmail.com"; 

$thankyouPage = "";

 

 

session_start();

if (!empty($_POST)) {

  foreach ($_POST as $key=>$value) {

      $_POST[$key] = stripslashes($_POST[$key]);

    $_POST[$key] = htmlspecialchars($_POST[$key],ENT_QUOTES);

  }

}

if (isset($_POST['send']) AND isset($_SESSION['msgCount'])) {

  if ($_SESSION['msgCount'] >= "3") $alert = "Only 3 messages can be s

+ent per session.";

  if (empty($alert)) {

    $_SESSION['msgCount']++;

    putenv('TZ=EST5EDT'); // eastern time

    $headers  = 'MIME-Version: 1.0' . "\r\n";

    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"

+;

    $message = "<table cellpadding='5' border='1'>";

    foreach ($_POST as $key => $value)

      if (!preg_match("(^send)",$key)) {

        $value = wordwrap($value,65,"<br />");

        $message .="<tr><td><b>$key</b></td><td>$value</td></tr>";

 

 

      }

    $message .= "</table>";   

    $message .= "<br />Time of the message: ".date(" F d  h:ia")."<br

+/>";

    $message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."<br />";

    $message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."<

+br />";

    $subject = $_SERVER['HTTP_HOST']." Message";

    mail($emailAddress,$subject,$message,$headers);

    if (!empty($thankyouPage)) {

      header('location: '.$thankyouPage);

      die();

    }

    unset($_POST);

 

    $alert = "Your enquiry has been sent, we will respond as soon as p

+ossible.";

  }

}

if (!isset($_SESSION['msgCount'])) $_SESSION['msgCount'] = 0;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.