Forum Moderators: open
I'm trying to figure out if you can send a form to e-mail without any server side instructions ; just by using some javascript code.
I looked up on google, reading for about 3 hours but couldn't have come to anything yet. Everywhere it says that it's not possible, but i think i saw once something like that.
I simply have a small form, which on submit i don't want to load another page. Just a short message displayed in the form's div telling that it has been sent.
Thanks,
this is tottally untest and written in a few seconds, but will give you and idea of what i mean.
function sendMail(formName, emailAddress){
to = emailAddress;
subject = "A test email";
body = "Hello,\n\n This is a test message from your site \n\n Input Box 1: " + document.formName.inputboxname.value + "\n Input box 2: " + document.formName.inputbox2name.value;
link = "mailto: "+to+"?subject="+subject+"&body="+body;
var out = "<iframe src="+link+"' width='0' height='0' name='mailSend' id='mailSend'></iframe>";
document.write(out);
}
[edited by: Kings_on_steeds at 7:39 pm (utc) on Feb. 25, 2009]
If you use a web-based interface like yahoo.com, hotmail.com, etc., it will not work.
If you use Outlook, Eudora, Thunderbird, etc., and your mail program is registered in your browser as the email "helper" program, when clicked it will open that email in the mail program ready to send.
Question, is the reason for no server script that you dont want to reload the page? because you could used ajax to send the email, which would make the process much cleaner.
Basically, you need a server-side script in order to make it a smooth, seamless, reliable process. Relying on the client to send the email is not seamless and is certainly not reliable. Yes, you could use AJAX to call a server-side script that then sends the email - no page refresh.