Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ktbubster

macrumors 6502a
Original poster
Jan 20, 2007
794
1
US
Hey all,

I'm having an issue. I'm trying to code a simple form so that people can enter in their email, phone, etc and when they click submit it will be sent to my email address. I got some code offline that I thought would work, but while the form and everything works, the submit button doesn't work so I don't get the information sent to me. Could someone help me and let me know what's wrong?

I substituted emailemail@hotmail.com for where my address i thought was supposed to go. Am i missing another place or did I just make a typing error?
Code:
<TITLE></TITLE> 

<script language="javascript"> 
   function SendEmail(frm){ 
     var emailAddress="emailemail@hotmail.com" 
    var message = "name:" + frm.txtName.value + "\n"; 
    message = message +"phone:" +  frm.txtold phone.value; 
    message = message +"email:" + frm.txtemail.value; 
    document.location.href = "mailto:"+emailemail@hotmail.com+"?subject=Test Mail&body="+escape(message); 
   } 
</script> 

<BODY> 
<form name="frmSendEmail" > 
<TABLE> 
<TR> 
<TD vAlign=center align=right width="35%"> 
name: 
</TD> 
<TD width="65%"><input type=text name=txtold value=""></TD></TR> 
<TR> 
<TD vAlign=center align=right width="35%"> 
phone: 
</TD> 
<TD width="65%"><input type=text name=txtpass value=""></TD></TR> 
<TR> 
<TD vAlign=center align=right width="35%"> 
email: 
</TD> 
<TD width="65%"><input type=text name=txtpass value=""></TD></TR> 
<TR><TD vAlign=center align=center width="100%" colspan=3> 
<INPUT TYPE="button" name="submit" Value="submit" onclick="SendEmail(this.form)"> 
</TD></TR> 
</TABLE> 
</form> 
</BODY>
 
I don't know enough about javascript yet to aid in how the script works but form my understanding of dealing with forms your form only have a name and no method or action. Usually a form would start like this:

HTML:
<form action="processme.php" method="post">
 
Try this for the script block,
PHP:
<script type="text/javascript">
   function SendEmail(frm) {
     var emailAddress = "emailemail@hotmail.com";
     var message = "name: " + frm.txtName.value + "\n";
     message +=  "phone: " +  frm.txtold phone.value + "\n";
     message += "email: " + frm.txtemail.value + "\n";
     document.location = "mailto:" + emailAddress
       + "?subject=Test Mail&body=" + escape(message);
   }
</script>
Then some mods to your HTML,
HTML:
<form name="frmSendEmail" onsubmit="SendEmail(this)">
...
<INPUT TYPE="submit" name="submit" Value="submit">
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.