Jump to content
Sign in to follow this  
sandesh.acharya

HELP please

Recommended Posts

i have a website with simple contact form that asks

 

1. Name

2. E-mail

3. Tel

4. Subject

5. Comments

 

the simple form is in .htm format and uses .php file for data submission.

 

now, problem is that someone stupid submits the contact form without any text (so i receive hundreds of blank e-mals everyday).

 

can you please suggest some script that prevents blank field from being submitted?

 

i searched around the net too but couldn't get exact solution.

 

for your info i have copied scripts of 'submit.htm' file and 'sendmail.php' files

 

 

CODE FROM MY submit.htm FILE that has contact form

 

 

 

 

CODE FROM MY submit.php FILE that receives data from submit.htm file and processes e-mail

 

 

<?php

/////////////////////////////////////////////////////////////

 

 

if (!empty($_POST)){

$redirect = "thanks.htm";

$subject = $_POST['Subj'];

$to = "my@emailaddress.com";

$from = $_POST['UserEmail'];

$message = "Information submitted on " . date( "l, F d, Y") . "\n

------------------------------------------------\n

Name: {$_POST['Name']}\n

E-mail: {$_POST['UserEmail']}\n

Tel: {$_POST['Tel']}\n

Subject: {$_POST['Subj']}\n

Comments:\n\n{$_POST['Comments']}\n\n";

 

mailIt($to, $from, "", "", $subject, $message);

echo " message received - thank you";

 

if ($redirect != "thanks.htm") header("Location: {$redirect}");

}

 

 

////////////////////////////////////////////////////////////

// The actual mail function.

 

function mailIt($to, $from, $cc, $bcc, $subject, $message){

if (!is_array($to)){

$to = "{$to}";

}

else{

foreach($to as $to_nick=>$to_mail){

$to_arr[] = "{$to_mail}";

}

$to = implode(', ', $to_arr);

}

 

if (!is_array($from)){

$from = "{$from}";

}

else{

$from = key($from[0]);

}

 

 

 

/* To send HTML mail, you can set the Content-type header. */

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

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

 

/* additional headers */

$headers .= "To: {$to}\r\n";

$headers .= "From: {$from}\r\n";

if ($cc != "") $headers .= "Cc: {$cc}\r\n";

if ($bcc !="") $headers .= "Bcc: {$bcc}\r\n";

 

/* and now mail it */

echo mail($to, $subject, $message, $headers);

 

 

}

 

?>

Share this post


Link to post
Share on other sites
i have a website with simple contact form that asks

 

1. Name

2. E-mail

3. Tel

4. Subject

5. Comments

 

the simple form is in .htm format and uses .php file for data submission.

 

now, problem is that someone stupid submits the contact form without any text (so i receive hundreds of blank e-mals everyday).

 

can you please suggest some script that prevents blank field from being submitted?

 

i searched around the net too but couldn't get exact solution.

 

for your info i have copied scripts of 'submit.htm' file and 'sendmail.php' files

 

 

CODE FROM MY submit.htm FILE that has contact form

 

 

 

 

CODE FROM MY submit.php FILE that receives data from submit.htm file and processes e-mail

 

 

<?php

/////////////////////////////////////////////////////////////

 

if ($Name == ""){$error = "$error

  • No username given
    \n";}

    if ($UserEmail == ""){$error = "$error

  • No emailgiven
    \n";}

    if ($Tel== ""){$error = "$error

  • No Tel given
    \n";}

     

     

    if (!empty($_POST)){

    $redirect = "thanks.htm";

    $subject = $_POST['Subj'];

    $to = "my@emailaddress.com";

    $from = $_POST['UserEmail'];

    $message = "Information submitted on " . date( "l, F d, Y") . "\n

    ------------------------------------------------\n

    Name: {$_POST['Name']}\n

    E-mail: {$_POST['UserEmail']}\n

    Tel: {$_POST['Tel']}\n

    Subject: {$_POST['Subj']}\n

    Comments:\n\n{$_POST['Comments']}\n\n";

     

    mailIt($to, $from, "", "", $subject, $message);

    echo " message received - thank you";

     

    if ($redirect != "thanks.htm") header("Location: {$redirect}");

    }

     

     

    ////////////////////////////////////////////////////////////

    // The actual mail function.

     

    function mailIt($to, $from, $cc, $bcc, $subject, $message){

    if (!is_array($to)){

    $to = "{$to}";

    }

    else{

    foreach($to as $to_nick=>$to_mail){

    $to_arr[] = "{$to_mail}";

    }

    $to = implode(', ', $to_arr);

    }

     

    if (!is_array($from)){

    $from = "{$from}";

    }

    else{

    $from = key($from[0]);

    }

     

     

     

    /* To send HTML mail, you can set the Content-type header. */

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

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

     

    /* additional headers */

    $headers .= "To: {$to}\r\n";

    $headers .= "From: {$from}\r\n";

    if ($cc != "") $headers .= "Cc: {$cc}\r\n";

    if ($bcc !="") $headers .= "Bcc: {$bcc}\r\n";

     

    /* and now mail it */

    echo mail($to, $subject, $message, $headers);

     

     

    }

     

    ?>

  •  

    Share this post


    Link to post
    Share on other sites

    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.   Paste as plain text instead

      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.

    Loading...
    Sign in to follow this  

    ×
    ×
    • Create New...

    Important Information

    By using this site, you agree to our Terms of Use.