I'm writing a HTML page with a registration button that should just silently send an email without opening the local mail client. Here is my HTML:
<form method="post" action="">
<input type="text" id="email_address" name="name" placeholder="Enter your email address..." required>
<button onclick="sendMail(); return false">Send Email</button>
</form>
... and here is my JavaScript code:
<script type="text/javascript">
function sendMail() {
var link = 'mailto:hello@domain.com?subject=Message from '
+document.getElementById('email_address').value
+'&body='+document.getElementById('email_address').value;
window.location.href = link;
}
</script>
The code above works... but it opens the local email client. If I remove the return
statement in the onclick
attribute like this:
<form method="post" action="">
<input type="text" id="email_address" name="name" placeholder="Enter your email address..." required>
<button onclick="sendMail()">Send Email</button>
</form>
... then the email is not sent at all. Am I missing something?
Any help would be reeeally appreciated :-)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…