processing form to be sent to email adress

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

processing form to be sent to email adress

Post by gavinbsocom »

Im unclear on if someone came to my site, and i wanted them to fill out a form and they pressed submit, how to get it sent to me?


<form action="<a href="mailto:whoever@.com"></a>" method="post">


can I put that as the action and it will get sent there? or is there a differnt way to do it?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the action property takes an url as value not an anchor element.
Try

Code: Select all

<html>
	<head>
		<title>client-side email</title>
	</head>
	<body>
		<A HREF="mailto:account@your.host?subject=A%20Subject&body=Some%20text">Send me an email</A>
		
		<form action="mailto:account@your.host?subject=A%20Subject" method="POST" enctype="text/plain">
			<input type="text" name="username" /><br />
			<textarea name="comment"></textarea><br />
			<input type="submit" />
		</form>
	</body>
</html>
Always add the enctype property. Without netscape/mozilla-based browsers will not include the field values
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post by gavinbsocom »

thats amazing, thankyou, but one quick question. why do you need the ? inbetween the email and the other thing. and 2 is subject a set thing can i chage thesubject to subject=info? also what does the enctype do? encript it?

<html>
<head>
<title>client-side email</title>
</head>
<body>
<A HREF="mailto:account@your.host?subject=info">Send me an email</A>

<form action="mailto:account@your.host?subject=info" method="POST" enctype="text/plain">
<input type="text" name="username" /><br />
<textarea name="comment"></textarea><br />
<input type="submit" />
</form>
</body>
</html>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the ? in a link separates the path from the parameters, i.e. subject is the parameter-name and info the value of this parameter .
take e.g. a look at the link that lead you here
viewtopic.php?t=13532
t=13532 is the parameter name/value pair that the script uses to find the thread you wanted.
and the common mailto:// implementation uses the parameter subject to fill in the subject-field

for enctype read http://www.w3.org/TR/html4/interact/for ... ef-enctype
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

umm.. you might want to mention that you'll need to use asp or php to send e-mail in a form in xhtml. possibly html4.01 as well. i think thats been deprecated
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post by gavinbsocom »

yah i was wondering about that, cause when I submitted the form it opened outlook expres.. I want it to just send it to the designated email adress. I would like to do it in php...can any one just give me a link or a little help on where to get started. Thankyou very much.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

http://www.php.net

search for the function: mail
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

hmm... on second thought i will.... here's an outline of a self processing form, just so you can use it to create one to play with...

Code: Select all

<?php
if(isset($_POST['process'])){
  $err=FALSE; $errs=array();
  /* make sure everything is ok (if not, set err to TRUE and place errors in errs array) */
  if(!($err)){
   /* set up the body */
   /* set up the headers */
   /* set up the subject */
   mail($to, $sub, $body, $headers); // send the mail
   }
}

if((!(isset($_POST['process'])))||($err)){ // if process isn't set, OR there's an error

/* give the frm, and any possible error messages */

}

?>
Post Reply