Form Coding help.

  • Thread starter Thread starter Super-Supra
  • 28 comments
  • 2,418 views

Super-Supra

(Banned)
Messages
4,111
Code:
 <form method="POST" action="mailto:mangatsunny@hotmail.com">

On my contact form, it opens up in Outlook Express, is there anyway to make it send the email straight to my account?
 
Well, then you'd have to provide an input box and all that good stuff... nothing I'm knowledgeable about.
 
Ah. In that case, maybe you could just explore the source code used when sending a GTP member an email?
 
um, I'm no HTML buff, but when you click on that link it prompts the computer to open outlook so you can write and send an email (it's automatically addressed to the hotmail account in the coding). If that's your link, it won't open your personal inbox; how is a 60-character code supposed to know the user who is logged on to the computer that clicked it; let alone the computer that clicked it! Use some common sense here, Sunny...
 
Originally posted by Jpec07
um, I'm no HTML buff, but when you click on that link it prompts the computer to open outlook so you can write and send an email (it's automatically addressed to the hotmail account in the coding). If that's your link, it won't open your personal inbox; how is a 60-character code supposed to know the user who is logged on to the computer that clicked it; let alone the computer that clicked it! Use some common sense here, Sunny...
I think you're misunderstanding what he wants... he wants an input box on the webpage where someone can type directly into it (much like a forum input box), then when they click "Submit" it'll be sent to Sunny's email account. By default, when you click on a mailto link, your browser will hand off the task to an outside email client... he wants it to send him an email from an input box, like if you send an email from GTP to another member.
 
Oh, I see now (even though I have no clue how to do it). The extent of my HTML abilities is placing pictures and links on a page, so I don't know how to help you...
 
Originally posted by Sage
I think you're misunderstanding what he wants... he wants an input box on the webpage where someone can type directly into it (much like a forum input box), then when they click "Submit" it'll be sent to Sunny's email account. By default, when you click on a mailto link, your browser will hand off the task to an outside email client... he wants it to send him an email from an input box, like if you send an email from GTP to another member.

EXACTLY!
 
okay, you need a cgi or php script in order to do this...

i can give these to you if you wish...its easier in php because you dont need a data parsing subroutine....i can dig one out if you really wish...

it takes a form with inputs, say name, email address and message and when submitted it sends it to any recipient you want, including yourself and has a from line from the email addy you specified in the form...

then you check your email and its there...:)
 
TurboSmoke is correct. This is because the e-mail is sent by the form handler (whichever file is in the "action" attribute).

I can also give you a really simple universal PHP script to send mail from a form.
 
I think my server supports php. Anyways, I'll give it a shot with php.

I have the whole form ready, all I need done is for the SUBMIT button to send that form to my email adderess.
 
It has to be an action. I ran into this problem on my old website and got it worked out. Thats actually where I pulled the code from.

Code:
<form action="mailto:mangatsunny@hotmail.com" method="post">
 
Hold on, I'll just edit that in Notepad, I'll see what the result is.


Ok, I just did that. I tested it out, and what happens is it asks me in Outlook Express, if I want to send it and stuff, I'll setup a test page.

Hold up.
 
Originally posted by Super-Supra
http://sunny.kinesophobia.com/form.htm

There's the link.

Still not working. Here, look at the code I used for my website (It's down now so I don't mind you seeing the whole thing)

Code:
<!-- 
//      Oh, so you want the code for this site? Stop right there, kid.
//      Go learn HTML if you want a site. If I find that you have 
//      anything of mine without permission I'll have your site 
//      shut-down so fast you won't even be able to blink. Thank You!
//                                  					             
//                                                                     -Ian Geiger
                                                                                                              -->
<head>

<title>.::Gran Turismo Source::.</title>
<STYLE>
<!--
A{text-decoration:none}
-->
</STYLE>
</head>

<body bgcolor="#555555" background="" text="white" link="#eeeeee" vlink="#eeeeee" alink="#eeeeee">
<FONT FACE="verdana" size="-2">
<CENTER>
<table  width="90%" border="1" cellspacing="0" cellpadding="1" bgcolor="#555555" bordercolor="#555555">
	<tr>
		<td  align="center">
			<FONT FACE="verdana" size="-2">
<b><a href="main.html">HOME</a> | <a href="links.html">LINKS</a> | <a href="staff.html">STAFF</a> | <a href="affiliates.html">AFFILIATES</a> | <a href="mailto:kosmikfool19@hotmail.com">CONTACT</a></b>
		</td>
	</tr>
</table>
<br>
  <br>
   <CENTER>
<img src="gtsourcetitlebanner.gif" alt="Gran Turismo Source">
<br>
  <br>
    <br>
<!-------------------------------------------------------------------------------------------------------------------LEFT---->
<TABLE BORDER="0" ALIGN="left" WIDTH="130" cellpadding="3" cellspacing="1" bgcolor="black">

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2">Menu</TD></TR>

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<font face="verdana" size="-2" color="black"><b>
<a href="main.html">Home</a><br>
<a href="staff.html">Staff</a><BR>
<a href="links.html">Links</a><BR>
<a href="affiliates.html">Affiliates</a>
</B></tr></td>



<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2">Gran Turismo</TD></TR>

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<font face="verdana" size="-2" color="black"><b>
<a href="gtmanu.html">Car Manufacturers</a><br>
<a href="gtreviews.html">Reviews</a><BR>
<a href="gtcheats.html">Cheats/Tips</a><BR>
<a href="gtscreens.html">Screenshots</a><BR>
</B></tr></td>



<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2">Gran Turismo 2</TD></TR>

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<font face="verdana" size="-2" color="black"><b>
<a href="gt2manu.html">Car Manufacturers</a><br>
<a href="gt2reviews.html">Reviews</a><BR>
<a href="gt2cheats.html">Cheats/Tips</a><BR>
<a href="gt2screens.html">Screenshots</a><BR>
</B></tr></td>



<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2">Gran Turismo 3 </TD></TR>

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #111111;">
<font face="verdana" size="-2" color="black"><b>
<a href="gt3manu.html">Car Manufacturers</a><br>
<a href="gt3reviews.html">Reviews</a><BR>
<a href="gt3cheats.html">Cheats/Tips</a><BR>
<a href="gt3screens.html">Screenshots</a><BR>
</B></tr></td>





<TABLE BORDER="0" ALIGN="CENTER" WIDTH="480" cellpadding="3" cellspacing="1" bgcolor="black">

<tr bgcolor="#38395a"><td style="font-family: arial; font-size: 12px; color: #000000;">
<font face="verdana" size="-2" color="white">


<table>
<tr>
<td bgcolor="#dddddd">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2"><b>
Sign-Up 
</td>

<tr><td colspan="3">
<FONT FACE="VERDANA" COLOR="#000000" SIZE="-2">
<!-- PUT STAFF SIGN-UP IN SPACE PROVIDED BELOW-USE AS MANY LINES AS NEEDED -->
Wanna be a part of the staff? Just fill out this form and you could be the next member of GTS. You must have HTML experience and have general knowledge of the GT series. Please note, I only take so many submissions at a time because of the trouble I have to go through to open these forms on my older computer. So DON'T SEND ME MULTIPLE SUBMISSIONS! It's a pain and I might ignore you.
<br>
  <br>
<form action="mailto:kosmikfool19@hotmail.com" method="post">
<input type="text" name="var name" size="40" maxlength="80" value="Name">
<br><br>
<input type="text" name="var name" size="40" maxlength="80" value="Sex">
<br><br>
<input type="text" name="var name" size="40" maxlength="80" value="E-mail">
<br><br>
Additional Info:
<br>
<textarea name="variable name" rows="3" cols="40"></textarea>
<br><br>
Why do you want to be on the Staff?
<textarea name="variable name" rows="3" cols="40"></textarea>
<br>
<br>
<br><input type="submit" value="Submit">&nbsp;&nbsp;<input type="reset" value="Reset">
</form>
<!-- END STAFF SIGN-UP HERE -->
</td></tr></table>
</td></table>
<br>
  <br>
    <br>
      <br>

</td></tr></table>
</td></table>





</table>


</body>
</html>
 
OK, you guys aren't getting the key point here:

You need to send the form to a form handler. There's no point simply putting a mailto: link in the action attribute as IE doesn't know what to go that. And the method="POST" doesn't mean "use e-mail".

OK then, here's a PHP form handler for you. Call it something like "formmailer.php", and then send your form to it with this tag:

<form action="formmailer.php" method="post">

PHP:
/*
Generic Form Handler. Delivers all form fields via e-mail to specified
recipient. Form code by giles-guthrie.com
*/

// First build the text of the e-mail
$mailtext = "Here is the result of your form. It is delivered as Key (i.e. form field name";
$mailtext .= "and Value pairings.\n\n";
while(list($Key, $Val)= each($_POST)) 
{
  if($Key == "Submit")
 {
    break;
 }
 $mailtext .= $Key." = ".$Val."\n";
}

// Now call the mail() function
$recipient = "surveys@mydomain.com";
$success = mail($recipient, "Output of Form ".$_ENV["HTTP_REFERER"], $mailtext);
if($success)
{
  echo "Form Mail Sent";
}
else
{
  echo "Mail error";
}

If you have any queries on what each part of the code does, I recommend you refer to the PHP manual at www.php.net.
 
No Kosmik, you didnt do it using HTML, because it cant be done using HTML alone...

Giles' solution uses a server side script that processes the email request on its own using the servers built in mailing functions...your solution uses a local installation of OE which is messy if you do not have a pop3 email account and OE isnt set up which, unless its a business computer, chances are it wont be set up for an outlook account....

all you have to do here is type your message into the html form and press submit.....and thats it! the script handles everything from there....its the standard way to produce an email from and really not that difficult...

here is the same thing in perl, a cgi script written by me....

the regular expression, i had a bit of help with but the rest is mine....

---------------------------

#!/usr/bin/perl

require "parsedata.dat";
&Parse_Form;
print "Content-type: text/html\n\n";

$name = $formdata{'name'};
$email = $formdata{'email'};
$phone = $formdata{'phone'};
$nature = $formdata{'nature'}; # nature of enquiry
$enquiry = $formdata{'enquiry'};
$youremail = joebloggs@somedomain.com; # the email address where you want to send your comments.


open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;

print MAIL "To: $youremail\n";
print MAIL "From: $email\n";
print MAIL "Subject: $nature\n";
print MAIL "\nName: $name\n";
print MAIL "Telehone Number: $phone\n\n";
print MAIL "Please reply to: $email\n\n";
print MAIL "Enquiry details: $enquiry\n";

close (MAIL);


print <<"HTML code";

<HTML>
<HEAD>
<TITLE>Thanks for Your Comments</TITLE>
<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=http://www.yourdomain.com/thanks.php">
</HEAD>

<BODY TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" BGCOLOR="\#ffffff">
Processing request. One moment please...
</BODY>
</HTML>

HTML code

sub ErrorMessage {
print "<P>&nbsp <P><FONT SIZE=5 COLOR=\"RED\">something is wrong with the mail script";
exit;
}


this data passing subroutine is stored in a seperate file called parsedata.dat

sub Parse_Form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);

if ($ENV{'QUERY_STRING'}) {
@getpairs =split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}

foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~s/<!--(.|\n)*-->//g;

if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
1;

this part takes the name/value pairs from your form and splits them up into variables...but php does this step automatically for you....thats why its easier and more efficient....but i leaned this first before php came along...


your form will then have 5 inputs, name, email, phone number, nature of enquiry and enquiry details and the name attibutes of your input tags will have to correspond exactly with the names stated in the script, else you'll get a server error....and you'll also have to make sure you set your file permissions to the correct value...ie 755 for the exectuable script and 666 for the subroutine...

you action statement would be

<form action="mailscript.cgi" method=post>

hope this helps...
 
supra, if you want to go down this route and use my script, i guarantee that it works beautifully as it is, i have spend years reducing it to its simplest form and its very easy to set up....

if you need instructions on how to do that just ask....its free for you to use...:) your web host will need to have a cgi-bin directory for you to use....ask them...

TS
 
Turbo, I'll use yours because the one Kosmik gave me didn't work. I tested it out last night, and when I pressed Submit, nothing happened.
 
GilesGuthrie
OK, you guys aren't getting the key point here:

You need to send the form to a form handler. There's no point simply putting a mailto: link in the action attribute as IE doesn't know what to go that. And the method="POST" doesn't mean "use e-mail".

OK then, here's a PHP form handler for you. Call it something like "formmailer.php", and then send your form to it with this tag:

<form action="formmailer.php" method="post">

PHP:
/*
Generic Form Handler. Delivers all form fields via e-mail to specified
recipient. Form code by giles-guthrie.com
*/

// First build the text of the e-mail
$mailtext = "Here is the result of your form. It is delivered as Key (i.e. form field name";
$mailtext .= "and Value pairings.\n\n";
while(list($Key, $Val)= each($_POST)) 
{
  if($Key == "Submit")
 {
    break;
 }
 $mailtext .= $Key." = ".$Val."\n";
}

// Now call the mail() function
$recipient = "surveys@mydomain.com";
$success = mail($recipient, "Output of Form ".$_ENV["HTTP_REFERER"], $mailtext);
if($success)
{
  echo "Form Mail Sent";
}
else
{
  echo "Mail error";
}

If you have any queries on what each part of the code does, I recommend you refer to the PHP manual at www.php.net.
I tried this and it doesn't sto work, I think that this is because my website has banner ads on it and it recognises a .php page as a web page and ads the banner code to it. Would this be the cause of my problem?

Also when you click submit the page with your php code in it loads and it is just the raw code underneath a banner ad.

Blake
 
Blake
I tried this and it doesn't sto work, I think that this is because my website has banner ads on it and it recognises a .php page as a web page and ads the banner code to it. Would this be the cause of my problem?

Also when you click submit the page with your php code in it loads and it is just the raw code underneath a banner ad.

Blake

Well, your host may have some spurious code in place, I'm not sure. Are you surrounding my code block with the <?php ?> markers?
 
Ok, that works, but the mail never goes to my inbox...

I changed $recipient = "surveys@mydomain.com"; so it has my email there, is their any other variables that I must change?

Blake
 
Back