Jump to content

Simple Form Post / Email issue


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?




$emailAddress = "bigL@gmail.com"; 

$thankyouPage = "";




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)) {


    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";


    if (!empty($thankyouPage)) {

      header('location: '.$thankyouPage);





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




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


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.