Current location: Hot Scripts Forums » Programming Languages » PHP » hi i just want to ask about email form...


hi i just want to ask about email form...

Reply
  #1 (permalink)  
Old 10-29-06, 02:33 PM
callmewhateveruwant callmewhateveruwant is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
hi i just want to ask about email form...

hi guys;

im quite new to php; ive praticed to use php to create an email form. i can create it within 2 files seperate. but now i just want to see if i can just use one file that can create an email form like that still can say Thank you if that visitor send mail.

I tried to use like this

PHP Code:

<? echo "<form method=\"post\" action=\"contact.php?action=check\">";

$ipi $_SERVER['REMOTE_ADDR'];
$httprefi $_SERVER['HTTP_REFERER'];
$httpagenti $_SERVER['HTTP_USER_AGENT'];

echo 
"<div align=\"center\">
<input type=\"hidden\" name=\"ip\" value=\" echo 
$ipi;\" />
<input type=\"hidden\" name=\"httpref\" value=\"echo 
$httprefi;\" />
<input type=\"hidden\" name=\"httpagent\" value=\" echo 
$httpagenti; \" />";

echo 
"<br />
<br /> 
Message
<br />"
;
echo 
"<textarea name=\"notes\" cols=\"40\" rows=\"4\" class=\"message\"></textarea>
<br />
<input type=\"submit\" value=\"Send\" />
<br />
</div>
</form>"
;

if (
$action==check)
{

if(empty(
$visitor))
{
echo 
"Save my time by typing something plz";
break;
}
else
{

$todayis = (date('l, F j, Y g:i:s A'mktime(date('H') )));
$Receiver 'xxx@xxx.com' ;
$subject 'contact';
$notes stripcslashes($notes);
$message "Sent at: $todayis [EST]\n
Written at: 
$notes \n
Referral: 
$httpref \n";

$from "From: one man\r\n";
mail("$Receiver"$subject$message );
echo 
"thank you";
}
}
?>
it still works but just when it says thank you; it still have the form above it or when error also; can u guys please teach me how to:
-when success; it says thank you with the fresh screen (means dont have the form above)
- same when get error.
- of course all still in the same page
Thank you very much.
Reply With Quote
  #2 (permalink)  
Old 10-29-06, 03:05 PM
odi's Avatar
odi odi is offline
Newbie Coder
 
Join Date: Oct 2006
Location: Switzerland
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
OK, this is all no Problem.

Just some thoughts:
-get your variables using $_POST['notes'] instead of just using $notes (this is a security and good style issue )
-You don't have to send the IP and the useragent through the form, there values are available via $_SERVER also after the form was sent...

For your problem of the display of the form:
-give your submit button a name:
Then you can simply check if $_POST['submit'] has the value "Send" and then don't display the form:
PHP Code:

<? 

if ($_POST['submit'] != "Send") {
   echo 
"<form method=\"post\" action=\"contact.php?action=check\">";
   echo 
"<div align=\"center\">";
   echo 
"<br /><br /> Message<br />";
   echo 
"<textarea name=\"notes\" cols=\"40\" rows=\"4\" class=\"message\"></textarea><br />
   <input type=\"submit\" name=\"submit\" value=\"Send\" />
   <br />
   </div>
   </form>"

}
Reply With Quote
  #3 (permalink)  
Old 10-29-06, 03:31 PM
TheNixMaster TheNixMaster is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Also:

PHP Code:

echo "<div align=\"center\">

<input type=\"hidden\" name=\"ip\" value=\" echo 
$ipi;\" />
<input type=\"hidden\" name=\"httpref\" value=\"echo 
$httprefi;\" />
<input type=\"hidden\" name=\"httpagent\" value=\" echo 
$httpagenti; \" />"

should be

PHP Code:

echo "<div align=\"center\">

<input type=\"hidden\" name=\"ip\" value=\"
$ipi\" />
<input type=\"hidden\" name=\"httpref\" value=\"
$httprefi\" />
<input type=\"hidden\" name=\"httpagent\" value=\"
$httpagenti\" />"
Reply With Quote
  #4 (permalink)  
Old 10-29-06, 03:48 PM
callmewhateveruwant callmewhateveruwant is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
thanks a lot guys; Im trying to do it and thanks for the advices about security also
Reply With Quote
  #5 (permalink)  
Old 10-29-06, 03:56 PM
callmewhateveruwant callmewhateveruwant is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
may i ask one more question please ...

what do u mean by using $_POST['notes'] this one? i mean where to use it ?
- in the name in the form?
- or in this line
PHP Code:

$notes stripcslashes($notes); 

- or in here
PHP Code:

Written at$notes \
and i have a spare time could u tell me what is the security problem here?
Reply With Quote
  #6 (permalink)  
Old 10-29-06, 06:07 PM
odi's Avatar
odi odi is offline
Newbie Coder
 
Join Date: Oct 2006
Location: Switzerland
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
You already spotted the places where you have to use $_POST

In your current script you use the names of your form-fields as variable names, which is done by a PHP option called Register Globals. You can read everything about it and why it's insecure to use it here: http://www.php.net/register_globals


Hope it helps.
Reply With Quote
  #7 (permalink)  
Old 10-30-06, 09:55 AM
callmewhateveruwant callmewhateveruwant is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
thanks a lot
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tute: Create Email based Contact Form Grabber PHP 3 05-31-06 03:11 AM
Need Help in Email Registration Form jamal Script Requests 0 06-06-05 02:13 AM
form to anyone's email with Image Verification ghostrider632 PHP 1 05-11-05 09:08 AM


All times are GMT -5. The time now is 05:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.