473,434 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Making a "Contact Us" Form

Hey umm how do you write a form that e-mails to you?
I so far have created a form and some labels and textboxes

Here is the code:
[HTML]<form name="contact" id="contact" method="put" action"#">
<label>Name: </label>
<p>
<input type="text" name="name" tabindex="1" class="ina"/>
</p>
<label>E-mail: </label>
<p>
<input type="text" name="email" tabindex="2" />
</p>
<label>Subject:</label>
<p>
<input type="text" name="subject" tabindex="3" />
</p>
<label>Message:
<p>
<textarea name="message"></textarea>
</p>
</label>
<p>
<input type="submit" name="Submit" value="Submit" tabindex="5" />
</p>
</form>[/HTML]

I would like to do a couple of things, first off make E-mail and Subject required, so that when a user presses Submit and if E-mail or Subject is not filled then a window pops up asking to fill in the all required fields.

Secondly, when the user presses submit I would like a message to be sent to an e-mail address(Example: support@coolkkids.com). The e-mail should be sent with all of the input the user provides.
Thank you any1 for their help.
Dec 18 '06 #1
25 14789
AricC
1,892 Expert 1GB
To send an email you are going to need a server side scripting language like PHP or ASP. Are you able to run either? You can google for a script or we can post an example.

HTH,
Aric
Dec 19 '06 #2
OK, umm i tried googling it didnt work, or im just really sucky at it.
So if u could put up an exapmle tat would be great

thank you
Dec 19 '06 #3
steven
143 100+
Does your web server support server side scripting languages such as PHP, PERL, JSP or ASP? If not, then an email form is not possible.
Dec 19 '06 #4
Does your web server support server side scripting languages such as PHP, PERL, JSP or ASP? If not, then an email form is not possible.
Luckily my web hosting site hostmonster.com does support CGI, Ruby (RoR), Perl, PHP, MYSQL
Dec 19 '06 #5
ronverdonk
4,258 Expert 4TB
Usually it is against my principle to show complete code in the forum, but this time I will make an exception. Especially since this answer really belongs in the PHP forum. The following sample shows a simple contact-me email form by Charles Reace. This code has ample comments, so you can work it out for your own requirements. Good luck![php]<?php
################################################## ###############################
#
# mail.php - general-purpose email form and script
#
# copyright June 2005 by Charles Reace
#
# This software available as open source software under the Gnu General Public
# License: http://www.gnu.org/licenses/gpl.html
#
################################################## ##############################
################################################## ##############################
# user-defined variables - update for your email address(es) ################################################## ##############################
# home page for link at top of page:
$home = "http://www.yourdomain.com/";
# Modify the following variables to set up where emails will be sent.
# $toName will be concatenated with a "@" and then $toDomain to create
# the complete email address.
$toName = "johndoe"; # the part that goes before the @
$toDomain = "yourdomain.com"; # the part that comes after the @
# uncomment and edit the next two lines if you want to cc someone:
$ccName = "ccname";
$ccDomain = "ccdomain.com";
# uncomment and edit the next two lines if you want to bcc someone:
$bccName = "bccname";
$bccDomain = "bccdomain.com";
#################################
# end of user-defined variables
##################################
# email address validation function
# kudos to http://iamcal.com/publish/articles/php/parsing_email/pdf/
function is_valid_email_address($email) {
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c\\x00-\\x7f';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}
# Init. some variables:
$error = "";
$success = FALSE;

# process form if submitted:
if(isset($_POST['submit'])){
foreach($_POST as $key => $val) {
if (empty($_POST[$key])) {
$error .= "You must enter a value for " .
ucwords(str_replace("_"," ",$key)) . ". ";
}
else {
if(get_magic_quotes_gpc()) {
$_POST[$key] = stripslashes($val);
}
}
if($key != 'message') {
$_POST[$key] = preg_replace('/[\r\n]/', ' ', $val);
}
}
if($_POST['email_address'] != $_POST['repeat_email']) {
$error .= "Email Address is not the same as Repeat Email. ";
}
elseif(is_valid_email_address($_POST['email_address']) == 0) {
$error .= "'{$_POST['email_address']}' does not appear to be a valid email address. ";
}
if(empty($error)) # no errors in input, so go ahead and email it.
{
$to = "$toName@$toDomain";
$headers = "From: ".preg_replace('/[\r\n]+/',' ', $_POST['email_address']);
if(!empty($ccName) and !empty($ccDomain)) {
$headers .= "\r\nCc: $ccName@$ccDomain";
}
if(!empty($bccName) and !empty($bccDomain)) {
$headers .= "\r\nBcc: $bccName@$bccDomain\r\n\r\n";
}
$headers .= "\r\nX-Mailer: PHP/" . phpversion();
$msg = "From {$_POST['name']} ({$_POST['email_address']})";
$msg .= "\n\n\n{$_POST['message']}";
echo "<pre>$headers"; exit;
$result = @mail($to,
stripslashes($_POST['subject']),
$msg,
$headers);
if(!$result) {
$error = "There was an unknown error while attempting to send your email.";
}
else {
header("Location: http://www.charles-reace.com/Email_Me/thanks.php");
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<title>Email Me</title>
<style type="text/css">
body {background-color:lemonchiffon;color:#002200;margin:10px 150px 0 150px; font-family:verdana,arial,sans serif;font-size:12px;}
.lab {margin-left:3px;display: block; float: left; width: 9em;}
legend {font-size:13px;font-weight:bold;}
</style>
</head>
<body>
<?php
if(!empty($error)){
echo "<p style='color: #c03;'>$error</p>\n";
}
?>
<h2>Email Me</h2>
<form action='<?php echo $_SERVER['PHP_SELF'] ?>' method=post>
<fieldset>
<legend>Your Contact Information</legend>
<p><label for='name' class='lab'>Name:</label>
<input type='text' name='name' id='name' size='30' maxlength='40'<?php
if(!empty($_POST['name'])){
echo "value='{$_POST['name']}'";
}
?>></p>
<p><label for='email_address' class='lab'>Email Address:</label>
<input type='text' name='email_address' id='email_address' size='30' maxlength='40'<?php
if(!empty($_POST['email_address'])){
echo "value='{$_POST['email_address']}'";
}
?>></p>
<p><label for='repeat_email' class='lab'>Repeat Email:</label>
<input type='text' name='repeat_email' id='repeat_email' size='30' maxlength='40'<?php
if(!empty($_POST['repeat_email'])) {
echo "value='{$_POST['repeat_email']}'";
}
?>></p>
</fieldset>
<p> </p>
<fieldset>
<legend>Message</legend>
<p><label for='subject' style="margin-left:3px;display: block; float: left; width: 9em;">Subject:</label>
<input type='text' name='subject' id='subject' size='50' maxlength='60'<?php
if(!empty($_POST['subject'])){
echo " value='{$_POST['subject']}'";
}
?>></p>
<p><label for='message' style="margin-left:3px;display: block; float: left; width: 9em;">Message:</label>
<textarea name='message' id='message' cols='50' rows='8'
style="width: 375px"><?php
if(!empty($_POST['message'])){
echo $_POST['message'];
}
?></textarea></p>
<p style="text-align: center;"><input type='submit' name='submit' value="Send Email"></p>
</fieldset>
</form>
</body>
</html>[/php]
Ronald :cool:
Dec 19 '06 #6
AricC
1,892 Expert 1GB
I was going to post one but that is more complete than the one I use
Dec 19 '06 #7
Well, I guess that will work (like I know!!!::sarcasm::)

I guess no harm in trying it out. Will tell you my results on Thursday.
Dec 19 '06 #8
ronverdonk
4,258 Expert 4TB
If you have questions/problems with that posted code sample, it is probably a good idea to post them in the PHP forum.

Not that I would want to lure you away from this forum, but it is likely that there are more PHP people in the php forum. So help will be quicker.

Ronald :cool:
Dec 19 '06 #9
AricC
1,892 Expert 1GB
If you have questions/problems with that posted code sample, it is probably a good idea to post them in the PHP forum.

Not that I would want to lure you away from this forum, but it is likely that there are more PHP people in the php forum. So help will be quicker.

Ronald :cool:
Maybe I should start hanging out in there if it's a happening place.
Dec 20 '06 #10
Well even though its not Thursday yet.
I copied the code and pasted it and I dont think it worked.
The link is cppinquiry.codetuts.com/contact.html

So wat do i do?
Dec 20 '06 #11
AricC
1,892 Expert 1GB
You didn't include that on your page correctly. The problem is you have basically two HTML pages in one.
Dec 21 '06 #12
UMM so how do i make it one?
Dec 21 '06 #13
AricC
1,892 Expert 1GB
UMM so how do i make it one?
Don't include the second
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html lang='en'>
  3. <head>
  4. <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
  5. <title>Email Me</title>
  6. <style type="text/css">
  7. etc....
  8.  
  9.  
Only include the form below this and the php above this.
Dec 21 '06 #14
i did do that but now its even more messed up
Dec 21 '06 #15
AricC
1,892 Expert 1GB
Post the page minus the php we gave you and we will re-post it with the correct code.

Aric
Dec 21 '06 #16
this is the original code w/o
my form itself

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  2. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  4. <head>
  5. <title>Codetuts-CppInquiry</title>
  6. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  7. <meta name="description" content="Your description goes here." />
  8. <meta name="keywords" content="your,keywords,goes,here" />
  9. <meta name="author" content="Brett Hillesheim" />
  10. <link rel="stylesheet" href="css.css" type="text/css" media="screen" />
  11. <link href="/contact.css" rel="stylesheet" type="text/css" media="screen" />
  12. </head>
  13.  
  14. <body>
  15. <div id="container">
  16. <div id="sitename">
  17. <h1>Codetuts-CppInquiry</h1>
  18.  
  19. </div>
  20.  
  21. <div class="tabsF" id="tabsF" dir="ltr" lang="en" onclick="http://www.codetuts.com
  22. ">
  23.   <ul>
  24.     <li><a href="index.html" title="CppInquiry"><span>Home</span></a></li>
  25.     <li><a href="programs.html" title="Programs/Source"><span>Programs/Source</span></a></li>
  26.     <li><a href="construction.html" title="Tutorials"><span>Tutorials</span></a></li>
  27.     <li><a href="construction.html" title="Articles"><span>Articles</span></a></li>
  28.  
  29.     <li><a href="construction.html" title="Forum"><span>Forum</span></a></li>
  30.     <li><a href="http://www.codetuts.com" title="Codetuts.com"><span>Codetuts</span></a></li>
  31.     <li class="linklist"><a href="construction.html" title="Archives"><span>Archives </span></a></li>
  32.     <li><a href="#" title="Contact Us"><span>Contact Us</span></a></li>
  33.     </ul>
  34. </div>
  35.  
  36. <div #tabsf>
  37.   <ul>
  38.     <il>
  39.     <a> <span></span></a>
  40.   </ul>
  41. </div>
  42. <div id="wrap">
  43. <br/><br/>
  44. <div id="rightside">
  45. <h1>Links</h1>
  46. <ul class="linklist">
  47. <li><a href="http://www.omnamo.com">Omnamo</a></li>
  48. <li><a href="construction.html">Gallery</a></li>
  49. <li><a href="construction.html">Affiliates</a></li>
  50.  
  51. <li><a href="http://oswd.org">OSWD.org</a></li>
  52. </ul>
  53.  
  54.  
  55. <h1>&nbsp;</h1>
  56.  
  57. <h1>Latest Announcements</h1>
  58.  
  59. <div id="scroll2">
  60.   <p><strong>Year of 2006 </strong></p>
  61.   <p><strong>Dec.11: </strong>Creation of Codetuts-Sravan ftp site</p>
  62.   <p><strong>Dec.13: </strong>First uploading of the site's layout thanks to Brett7481</p>
  63.   <p><strong>Dec. 15:</strong> Change of name to CppInquiry </p>
  64.   <p><strong>Dec. 16: </strong>Programs/Source section is up</p>
  65.   <p><strong>Dec. 16: </strong>Created "Under Constructions" pages for CppInquiry</p>
  66. </div>
  67. <h1>&nbsp;</h1>
  68. </div>
  69. <div id="contentalt" >
  70.   <div id="scroll">
  71.  
  72. </div>
  73. <p>&nbsp;</p>
  74. </div>
  75.  
  76. <div class="clearingdiv">&nbsp;</div>
  77. </div>
  78.  
  79. <div id="footer">@2006 Codetuts-CppInquiry| Design by <a href="http://www.ibentmywookie.org">Brett7481</a></div>
  80. </div>
  81. </body>
  82. </html>
  83.  
Dec 21 '06 #17
I need the form in the part where it says

[HTML]<div id="contenalt">
<div id="scroll2">

</div>
<p>&nbsp;</p>
</div>[/HTML]
Dec 22 '06 #18
AricC
1,892 Expert 1GB
I need the form in the part where it says

[HTML]<div id="contenalt">
<div id="scroll2">

</div>
<p>&nbsp;</p>
</div>[/HTML]
Inbetween the paragraph tags?
Dec 22 '06 #19
no between the div tags.
the div tags make like a scrollbox for the main content. I would like it there.

Thnks a ton
Dec 22 '06 #20
AricC
1,892 Expert 1GB
I don't have your style sheet but try this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ##################################################  ###############################
  3. #
  4. # mail.php - general-purpose email form and script
  5. #
  6. # copyright June 2005 by Charles Reace
  7. #
  8. # This software available as open source software under the Gnu General Public
  9. # License: http://www.gnu.org/licenses/gpl.html
  10. #
  11. ##################################################  ##############################
  12. ##################################################  ##############################
  13. # user-defined variables - update for your email address(es) ##################################################  ##############################
  14. # home page for link at top of page:
  15. $home = "http://www.yourdomain.com/";
  16. # Modify the following variables to set up where emails will be sent.
  17. # $toName will be concatenated with a "@" and then $toDomain to create
  18. # the complete email address.
  19. $toName   = "johndoe";         # the part that goes before the @
  20. $toDomain = "yourdomain.com";  # the part that comes after the @
  21. # uncomment and edit the next two lines if you want to cc someone:
  22. $ccName   = "ccname";
  23. $ccDomain = "ccdomain.com";
  24. # uncomment and edit the next two lines if you want to bcc someone:
  25. $bccName   = "bccname";
  26. $bccDomain = "bccdomain.com";
  27. #################################
  28. # end of user-defined variables 
  29. ##################################
  30. # email address validation function
  31. # kudos to http://iamcal.com/publish/articles/php/parsing_email/pdf/
  32. function is_valid_email_address($email) {  
  33.   $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';  
  34.   $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';  
  35.   $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
  36.           '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';  
  37.   $quoted_pair = '\\x5c\\x00-\\x7f';  
  38.   $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";  
  39.   $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";  
  40.   $domain_ref = $atom;  
  41.   $sub_domain = "($domain_ref|$domain_literal)";  
  42.   $word = "($atom|$quoted_string)";  
  43.   $domain = "$sub_domain(\\x2e$sub_domain)*";  
  44.   $local_part = "$word(\\x2e$word)*";  
  45.   $addr_spec = "$local_part\\x40$domain";  
  46.   return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
  47. }
  48. # Init. some variables:
  49. $error = "";
  50. $success = FALSE;
  51.  
  52. # process form if submitted:
  53. if(isset($_POST['submit'])){
  54.   foreach($_POST as $key => $val)  {
  55.       if (empty($_POST[$key]))    {
  56.          $error .= "You must enter a value for " .
  57.                     ucwords(str_replace("_"," ",$key)) . ". ";
  58.       }    
  59.       else  { 
  60.          if(get_magic_quotes_gpc())      {
  61.               $_POST[$key] = stripslashes($val);      
  62.          }    
  63.       }    
  64.       if($key != 'message')    {
  65.          $_POST[$key] = preg_replace('/[\r\n]/', ' ', $val);
  66.       }  
  67.   }  
  68.   if($_POST['email_address'] != $_POST['repeat_email'])  {
  69.     $error .= "Email Address is not the same as Repeat Email. ";  
  70.   }  
  71.   elseif(is_valid_email_address($_POST['email_address']) == 0)  {
  72.     $error .= "'{$_POST['email_address']}' does not appear to be a valid email address. "; 
  73.   }  
  74.   if(empty($error))  # no errors in input, so go ahead and email it.  
  75.   {
  76.     $to = "$toName@$toDomain";
  77.     $headers = "From: ".preg_replace('/[\r\n]+/',' ', $_POST['email_address']);
  78.     if(!empty($ccName) and !empty($ccDomain))    {
  79.       $headers .= "\r\nCc: $ccName@$ccDomain";
  80.     }
  81.     if(!empty($bccName) and !empty($bccDomain))    {
  82.       $headers .= "\r\nBcc: $bccName@$bccDomain\r\n\r\n";    
  83.     }    
  84.     $headers .= "\r\nX-Mailer: PHP/" . phpversion();
  85.     $msg = "From {$_POST['name']} ({$_POST['email_address']})";
  86.     $msg .= "\n\n\n{$_POST['message']}";
  87.     echo "<pre>$headers"; exit;
  88.     $result = @mail($to,
  89.                     stripslashes($_POST['subject']),
  90.                     $msg,
  91.                     $headers);
  92.     if(!$result)    {
  93.       $error = "There was an unknown error while attempting to send your email.";
  94.     }
  95.     else    {
  96.       header("Location: http://www.charles-reace.com/Email_Me/thanks.php");
  97.     }
  98.   }
  99. }
  100. ?>
  101. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  102. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  103. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  104. <head>
  105. <title>Codetuts-CppInquiry</title>
  106. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  107. <meta name="description" content="Your description goes here." />
  108. <meta name="keywords" content="your,keywords,goes,here" />
  109. <meta name="author" content="Brett Hillesheim" />
  110. <link rel="stylesheet" href="css.css" type="text/css" media="screen" />
  111. <link href="/contact.css" rel="stylesheet" type="text/css" media="screen" />
  112. </head>
  113.  
  114. <body>
  115. <div id="container">
  116. <div id="sitename">
  117. <h1>Codetuts-CppInquiry</h1>
  118.  
  119. </div>
  120.  
  121. <div class="tabsF" id="tabsF" dir="ltr" lang="en" onclick="http://www.codetuts.com
  122. ">
  123.   <ul>
  124.     <li><a href="index.html" title="CppInquiry"><span>Home</span></a></li>
  125.     <li><a href="programs.html" title="Programs/Source"><span>Programs/Source</span></a></li>
  126.     <li><a href="construction.html" title="Tutorials"><span>Tutorials</span></a></li>
  127.     <li><a href="construction.html" title="Articles"><span>Articles</span></a></li>
  128.  
  129.     <li><a href="construction.html" title="Forum"><span>Forum</span></a></li>
  130.     <li><a href="http://www.codetuts.com" title="Codetuts.com"><span>Codetuts</span></a></li>
  131.     <li class="linklist"><a href="construction.html" title="Archives"><span>Archives </span></a></li>
  132.     <li><a href="#" title="Contact Us"><span>Contact Us</span></a></li>
  133.     </ul>
  134. </div>
  135.  
  136. <div #tabsf>
  137.   <ul>
  138.     <il>
  139.     <a> <span></span></a>
  140.   </ul>
  141. </div>
  142. <div id="wrap">
  143. <br/><br/>
  144. <div id="rightside">
  145. <h1>Links</h1>
  146. <ul class="linklist">
  147. <li><a href="http://www.omnamo.com">Omnamo</a></li>
  148. <li><a href="construction.html">Gallery</a></li>
  149. <li><a href="construction.html">Affiliates</a></li>
  150.  
  151. <li><a href="http://oswd.org">OSWD.org</a></li>
  152. </ul>
  153.  
  154.  
  155. <h1>&nbsp;</h1>
  156.  
  157. <h1>Latest Announcements</h1>
  158.  
  159. <div id="scroll2">
  160.   <p><strong>Year of 2006 </strong></p>
  161.   <p><strong>Dec.11: </strong>Creation of Codetuts-Sravan ftp site</p>
  162.   <p><strong>Dec.13: </strong>First uploading of the site's layout thanks to Brett7481</p>
  163.   <p><strong>Dec. 15:</strong> Change of name to CppInquiry </p>
  164.   <p><strong>Dec. 16: </strong>Programs/Source section is up</p>
  165.   <p><strong>Dec. 16: </strong>Created "Under Constructions" pages for CppInquiry</p>
  166. </div>
  167. <h1>&nbsp;</h1>
  168. </div>
  169. <div id="contentalt" >
  170.   <div id="scroll">
  171.  
  172. <h2>Email Me</h2>
  173. <form action='<?php echo $_SERVER['PHP_SELF'] ?>' method=post>
  174. <fieldset>
  175. <legend>Your Contact Information</legend>
  176. <p><label for='name' class='lab'>Name:</label>
  177. <input type='text' name='name' id='name' size='30' maxlength='40'<?php
  178. if(!empty($_POST['name'])){  
  179.   echo "value='{$_POST['name']}'";
  180. }
  181. ?>></p>
  182. <p><label for='email_address' class='lab'>Email Address:</label>
  183. <input type='text' name='email_address' id='email_address' size='30' maxlength='40'<?php
  184. if(!empty($_POST['email_address'])){  
  185.   echo "value='{$_POST['email_address']}'";
  186. }
  187. ?>></p>
  188. <p><label for='repeat_email' class='lab'>Repeat Email:</label>
  189. <input type='text' name='repeat_email' id='repeat_email' size='30' maxlength='40'<?php
  190. if(!empty($_POST['repeat_email'])) {  
  191.   echo "value='{$_POST['repeat_email']}'";
  192. }
  193. ?>></p>
  194. </fieldset>
  195. <p> </p>
  196. <fieldset>
  197. <legend>Message</legend>
  198. <p><label for='subject' style="margin-left:3px;display: block; float: left; width: 9em;">Subject:</label>
  199. <input type='text' name='subject' id='subject' size='50' maxlength='60'<?php
  200. if(!empty($_POST['subject'])){  
  201.   echo " value='{$_POST['subject']}'";
  202. }
  203. ?>></p>
  204. <p><label for='message' style="margin-left:3px;display: block; float: left; width: 9em;">Message:</label>
  205. <textarea name='message' id='message' cols='50' rows='8'
  206. style="width: 375px"><?php
  207. if(!empty($_POST['message'])){  
  208.   echo $_POST['message'];
  209. }
  210. ?></textarea></p>
  211. <p style="text-align: center;"><input type='submit' name='submit' value="Send Email"></p>
  212. </fieldset>
  213. </form>
  214.  
  215.  
  216.  
  217.  
  218. </div>
  219. <p>&nbsp;</p>
  220. </div>
  221.  
  222. <div class="clearingdiv">&nbsp;</div>
  223. </div>
  224.  
  225. <div id="footer">@2006 Codetuts-CppInquiry| Design by <a href="http://www.ibentmywookie.org">Brett7481</a></div>
  226. </div>
  227. </body>
  228. </html>
Also you need to read the script there is information that you need to fill out in there like your email address.
Dec 22 '06 #21
CMK
1
There are a number of ways of doing this i.e. server side and client side. The suggestion below is client side using Javascript, this way you won't need a server to test it out, although you will for the second of your queries(some on to that later).

Right number 1: validating the form. You want to generate a pop up window when a user has not filled in a particular field. This is Javascript.

Here's what you do.
In the html change method="put" to "post"
<form method="post" id="contact" onsubmit="return checkall(this);" action="i'll come onto this later">

It's easiest to stick this your html rather than a separate file. In the 'Head' section use this.

<script type="text/javascript">

function checkall(contact)
{
if (contact.name.value == "")
{
alert("You must enter a name");
return (false);
}

if (contact.subject.value == "")
{
alert("You must enter your address");
return (false);
}


}
</script>

The code explained: 'function checkall(contact)' goes through the form validating whatever you have asked it to, in this script i.e. the name and subject fields.

'if (contact.name.value == "")' This says "if the contact form where the value of the field name is blank then print out the error message - which can say anything you want it to, if the fields are not blank then allow the form to be processed"

Number 2. This is where it gets a little more involved

In order to send the form, you'll need to use a 'sever side' language, in other words first of all you need to install a server. The server you use will depend upon which laguage you want to use to process the email. One such language is PHP, so rather than go through all the possibilities i'll stick to, how to do it using PHP.

PHP can be run on one of two servers, Apache or IIS.

The PHP code used to send the email

<?php
//these 'extract' the information written by the user from the name and subject fields
$name = $_REQUEST['name'] ;
$subject = $_REQUEST['subject'] ;

//sets the email address to send message from
ini_set("sendmail_from","the-email-address-you-want-to-use-to-send-the-email-from");

//takes the form "to-email address", "subject of the email", "then takes the 'subject and name' from the form"
mail("youremailaddressagain", "subject of message-Here's hoping this arrives, Fingers crossed!", "Comment:$subject", "From: $name");

//a little thankyou message
echo "A thankyou message-thankyou for message-or something";
?>

The backslashes are used as comments in the code and do not get processed.

Hope that helps! This is simple really, might not look it though.
Dec 22 '06 #22
wtf its not workin. I dont know what I'm doing wrong.

But anyways thanks and just want to point out that
when you go to the page cppinquiry.codetuts.com/contact.html
it starts to show some of the code starting from "$val"

So any suggesstions.
Dec 22 '06 #23
[quote=CMK]There are a number of ways of doing this i.e. server side and client side. The suggestion below is client side using Javascript, this way you won't need a server to test it out, although you will for the second of your queries(some on to that later).

Right number 1: validating the form. You want to generate a pop up window when a user has not filled in a particular field. This is Javascript.

Here's what you do.
In the html change method="put" to "post"
<form method="post" id="contact" onsubmit="return checkall(this);" action="i'll come onto this later">

It's easiest to stick this your html rather than a separate file. In the 'Head' section use this.

<script type="text/javascript">

function checkall(contact)
{
if (contact.name.value == "")
{
alert("You must enter a name");
return (false);
}

if (contact.subject.value == "")
{
alert("You must enter your address");
return (false);
}


}
</script>

QUOTE]


Ok first things first how does the computer know when to display the alert message and is "alert();" already defined somewhere (over the rainbow)!
And also can you explain "action" in the <form...>
Dec 22 '06 #24
Number 2. This is where it gets a little more involved

In order to send the form, you'll need to use a 'sever side' language, in other words first of all you need to install a server. The server you use will depend upon which laguage you want to use to process the email. One such language is PHP, so rather than go through all the possibilities i'll stick to, how to do it using PHP.

PHP can be run on one of two servers, Apache or IIS.

The PHP code used to send the email

<?php
//these 'extract' the information written by the user from the name and subject fields
$name = $_REQUEST['name'] ;
$subject = $_REQUEST['subject'] ;

//sets the email address to send message from
ini_set("sendmail_from","the-email-address-you-want-to-use-to-send-the-email-from");

//takes the form "to-email address", "subject of the email", "then takes the 'subject and name' from the form"
mail("youremailaddressagain", "subject of message-Here's hoping this arrives, Fingers crossed!", "Comment:$subject", "From: $name");

//a little thankyou message
echo "A thankyou message-thankyou for message-or something";
?>

The backslashes are used as comments in the code and do not get processed.

Hope that helps! This is simple really, might not look it though.
Now on to number too, are all those functions already defined (i.e ini_set(), mail())
Also what do the functions do, and what are the arguements according to my form(below) and my e-mail address "cppinquiry@codetuts.com"
[HTML]
<form method="post" id="contact" onsubmit="return checkall(this);" action="i'll come onto this later">
<label>Name: </label>
<p>
<input type="text" name="name" tabindex="1" class="ina"/>
</p>
<label>E-mail: </label>
<p>
<input type="text" name="email" tabindex="2" />
</p>
<label>Subject:</label>
<p>
<input type="text" name="subject" tabindex="3" />
</p>
<label>Message:
<p>
<textarea name="message"></textarea>
</p>
</label>
<p>
<input type="submit" name="Submit" value="Submit" tabindex="5" />
</p>
</form>
[/HTML]

heheh I stole ur form declaration heheheh

thanks for ur help
ill put ur name if u want in comments on this page, if you can help me with this goal
Dec 22 '06 #25
AricC
1,892 Expert 1GB
popnbrown are you still having problems with this?
Dec 29 '06 #26

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jason | last post by:
I'm struggling with this email code and I'm not php freak since I'm starting to learn php stuff. Could use some help... It seems that I get too many parse errors all over and cannot figure went...
20
by: Steevo | last post by:
For some reason I can't seem to get the contact form on our website to work any longer. I think I must have something wrong in the script because I keep getting an "Internal Server Error" upon...
4
by: Al Dykes | last post by:
I'm going to be collecting lots (a few thousand) email addys. Each of these people will be interested in recieving mail on one or more topics, with an open ended and growing number of topics....
17
by: Serge Fournier | last post by:
I would like to access the "contact" data in Outlook Express. Which reference do I have to use ? (I was thinking at "Office"). Thanks for any help
2
by: Matt | last post by:
delicious has a bookmark you can add to your toolbar of this form:...
1
by: H5N1 | last post by:
hi there the topic says it all. I have a outer join select statement in tableadapter that populates GridView, I want to make it updatetable, so I need to provide an update command for table...
7
by: popnbrown | last post by:
Anyone know how to write PHP that can take values that a user inputs into a form on a webiste and the e-mail those values to myself. In other words how do i write PHP code for a Contact Us Form?
1
by: kang jia | last post by:
how can i do contact us page? use mail function ??hmm.. but when i click "contact us" navigation. it will link the mailbox. how to do this linkage? i am quite new to PHP, maybe this problem seems...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.