I'd like to open an email automatically with To & subject, when the html page loads. I need to use only mailto functionality. Can someone help me how to do this?
Asked
Active
Viewed 5,078 times
3
-
Additionally you may find this question useful: [how-to-avoid-the-mailto-annoyance](http://stackoverflow.com/questions/891131/how-to-avoid-the-mailto-annoyance) – Arsen7 Apr 27 '12 at 07:20
2 Answers
9
Redirect the user to a mailto
link. This can be done with basic JavaScript:
location.href = "mailto:you@example.com?subject=Test+Message";
Just take into consideration the fact that:
- A lot of people use online email these days (GMail, hotmail, etc) - not me personally, but... other people.
- If the user has a desktop email program, you'll be forcing an unexpected window open on them.
- It's even worse if the user has a desktop email program, but has never set it up - as would be the case of most of the people in point 1. The window would open and then the whole "email setup" process would start.
Just be careful.

Niet the Dark Absol
- 320,036
- 81
- 464
- 592
2
try something like this
<html>
<head>
<script type="text/javascript">
function mymessage()
{
location.href = "mailto:you@example.com?subject=Hello";
}
</script>
</head>
<body onload="mymessage()">
</body>
</html>

srini
- 876
- 3
- 12
- 23
-
Yesterday it was working fine. Today i am getting an error in IE 9 with a pop-up saying " Another version of outlook is currently running. close it and try again". Working good in firefox And IE 8. – Sathish Apr 27 '12 at 07:43
-
1
-
1srini's example also works perfectly with PHP (and MySQL) code if you put the PHP code before the for example: location.href="mailto:?subject= Receipt&body="; – KarlosFontana Apr 18 '14 at 18:18