Click to See Complete Forum and Search --> : Automated Email in JavaScript


Dathor Verlox
06-27-2003, 06:27 AM
Does anyone know how to send an email using JavaScript automatically so the user clicks on something and it is sent without him/her knowing or it auto-sends at a certain point.?
I know how to do it in html but I would like to be able to use JavaScript variables as the addresses in the "to" box on the email. These variables are set by prompt boxes the user fills in.

Khalid Ali
06-27-2003, 09:30 AM
you can use mailto:command in html forms action attribute

action="mailto:ur_email@mail.com" method="post" enctype="text/plain"

However it does not necesarily be discreet..:-)

Dathor Verlox
06-30-2003, 06:31 AM
Can I use multiple JavaScript variables in this mailto command and if so where would they go?

Thanks

steelersfan88
06-30-2003, 01:14 PM
To send an email using javascript variables, you can use the script:

<script Language = "javascript">

var email = "email address"
var subject = "subject"
var body = "body"

document.write("<form name="form" action=\"mailto:"+ email +"\?subject="+ subject +"\&body="+ body +"\" method=\"post\" enctype=\"text/plain\"></form>")

</script>

To submit the form, you can use the <input type="submit"> or <input type="button" value="Submit" onclick="document.form.submit()"> methods.

Hope this helps

Dathor Verlox
07-01-2003, 05:57 AM
Thanks,
Thats great, can I use more than one email address by using multiple variables where you have the "email" variable?
Does the user have to click the button to submit or could I either submit it automatically without the users consent or have a hyperlink to submit it?
Sorry for pestering you.

Thanks:confused:

steelersfan88
07-01-2003, 11:54 AM
<script Language = "javascript">

var email = "email addresses"
// separate addresses by commas, no spaces //
var subject = "subject"
var body = "body"

document.write("<form name="form" action=\"mailto:"+ email +"\?subject="+ subject +"\&body="+ body +"\" method=\"post\" enctype=\"text/plain\"></form>")

</script>

<body onload="document.form.submit()">

This script should submit the form when the page loads, not requiring a user click.

nkaisare
07-01-2003, 12:11 PM
Originally posted by Dathor Verlox
Does the user have to click the button to submit or could I either submit it automatically
You can do either. Using onblur event-handler, you can submit the form as soon as user finishes entering info in a particular form field. Alternatively, you can submit the form on occurrance of any event, or a certain amount of time after page finishes loading. Clicking on submit button isn't required.

without the users consent
Unless you have a dumb user using Internet explorer, you can't have it email without permission. You can have server-side method (cgi/php etc, combined with onblur or other javascript event handlers) to do so, but not client-side javascript.

have a hyperlink to submit it?
Yes.
document.write("<a href=\"mailto:"+ email +"\?subject="+ subject +"\&body="+ body +"\"send me an email</a>")