Jump to content


Photo

HELP please


  • Please log in to reply
1 reply to this topic

#1 sandesh.acharya

sandesh.acharya

    Newbie

  • Members
  • Pip
  • 61 posts

Posted 06 October 2006 - 02:00 PM

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

<form method="POST" action="sendmail.php">
<input type="text" name="Name" >
<input type="text" name="UserEmail" >
<input type="text" name="Tel" >
<input type="text" name="Subj" >
<textarea rows="5" name="Comments" >
<input type="reset" value="Reset" >
<input type="submit" value="Submit" >
</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);


}

?>

#2 acchami

acchami

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 17 February 2007 - 11:32 AM

QUOTE(sandesh.acharya @ Oct 6 2006, 11:00 PM) View Post
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

<form method="POST" action="sendmail.php">
<input type="text" name="Name" >
<input type="text" name="UserEmail" >
<input type="text" name="Tel" >
<input type="text" name="Subj" >
<textarea rows="5" name="Comments" >
<input type="reset" value="Reset" >
<input type="submit" value="Submit" >
</form>



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


<?php
/////////////////////////////////////////////////////////////


if ($Name == ""){$error = "$error<li>No username given<BR>\n";}
if ($UserEmail == ""){$error = "$error<li>No emailgiven<BR>\n";}
if ($Tel== ""){$error = "$error<li>No Tel given<BR>\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);


}

?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users