Jump to content

Send a mail from a form ??


Meathook

Recommended Posts

Hi,All the W3school html examples works fine except one : "Send a mail from a form"All it does is opening an outlook email WITHOUT the text in the name, mail and comment text field.Is it because this form is deprecated?Here's the code of the example : <html><body><form action="MAILTO:someone@w3schools.com" method="post" enctype="text/plain"><h3>This form sends an e-mail to W3Schools.</h3>Name:<br><input type="text" name="name"value="yourname" size="20"><br>Mail:<br><input type="text" name="mail"value="yourmail" size="20"><br>Comment:<br><input type="text" name="comment"value="yourcomment" size="40"><br><br><input type="submit" value="Send"><input type="reset" value="Reset"></form></body></html>

Link to comment
Share on other sites

Correct. HTML is not able to auto-populate the e-mail without some help - it can't read your mind. So, here is what you could do:1.) find some javascript (sorry I don have any off hand) that will catch the form before it is submitted2.) then, find some script that will append your "method" attribute like so:action="mailto:someone@w3schools.com?subject=mysubject&message=mymessage"3.) make sure you substitue any spaces with %20 in your subject and message, or it won't work.

Link to comment
Share on other sites

Sorry for not being clear - your coding is correct in its syntax. But the <form> tag using "mailto:" to populate the body of an e-mail message is NOT possible by itself. Something needs to tell the browser what to goes in the subject and message.By default, the web browser looks to see if the "action" starts with "mailto:". If it does, then all the browser does is open the client's default mail application and passed it whatever appears after "mailto:". Most e-mail programs are built to parse the url variables "subject" and "message". But is up to the developer to populate those strings - that's where the javascript (in an HTML only environment) comes in to play.Did that help any?

Link to comment
Share on other sites

ok thanks,can you give an example of what I can add to the code to make it work?To the code we should add java or something to tell the form to put the 3 inputs IN the email ?w3schools shoud advice that the example ONLY works if there's java or something...

Link to comment
Share on other sites

Side note: t's javascript, not java. They're very different. :)One way of doing it is through not using a submit button, but use a regular button which calls a javascript function which then does some stuff with emailing and things and opens the email with the stuff. Where i am vague is where i don't know what to do. :)

Link to comment
Share on other sites

Actually you can send mail with action="mailto:.....It is the email client on the users machine, in this case Outlook Express, that screws things up. I have been able to successfully send forms like this (it was on a Intranet with web based email through Exchange so there were no email clients to mess up the process.So, your syntax and application of the example is indeed correct, just not a very reliable method due to issues with email clients.Note: not all email clients mess up the process, but Outlook does and since that is by default on most windows computers, whether used or not, it will be a huge obsticle.The javascript will work but I would suggest a server language to send the form.Hey Prof Dan, you must be a PHP guy! lol. Everytime I have seen you suggest a language it is PHP...I am the opposite...ASP.Net all the way. Not that there is anything wrong with PHP, I am just glad I got out of scripting langauges, I prefer compiled code, better for software dist.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...