Forum Moderators: open

Message Too Old, No Replies

Javascript mail function

         

junglesnail

6:16 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



Greetings to all,

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,

Kings on steeds

7:36 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



without a server side script you wouldnt be able to automaticlly mail the form, but you could build a mailto, using &body...

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]

rocknbil

9:26 pm on Feb 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard junglesnail, note that King's solution, or any other solution using a mailto: link, will only work if the user has a default mail program on their computer that is registered with the browser, and that is their "normal" method of sending and receiving mail.

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.

Kings on steeds

10:48 pm on Feb 25, 2009 (gmt 0)

10+ Year Member



yer thanks rocknbil, it isnt an ideal solution at all, but its as close as you can come without a service side script. 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.

penders

10:21 am on Feb 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.