Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html button to send email

Tags:

html

forms

email

How do I send an email with specified initial values for the headers subject and message from a button in html, such as this

<form method="post" action="mailto:email.com?subject=subject&message=message"> 

where subject and message are values fetched from a form?

like image 243
user544079 Avatar asked Apr 24 '11 20:04

user544079


People also ask

How do I make an email button in HTML?

The only way to send an e-mail with pure HTML and no PHP is to use the a element. Use the href property with the value "mailto:[email protected]". The only issue is that this will open their default mail client and they will have to manually click send via their mail client.

Which button is used to send an email?

After you address the message, press the Tab key to move to the message box and compose your message. When you finish, press Alt+ S to send the message.


2 Answers

You can use mailto, here is the HTML code:

<a href="mailto:EMAILADDRESS"> 

Replace EMAILADDRESS with your email.

like image 129
armn Avatar answered Sep 22 '22 04:09

armn


This method doesn't seem to work in my browser, and looking around indicates that the whole subject of specifying headers to a mailto link/action is sparsely supported, but maybe this can help...

HTML:

<form id="fr1">     <input type="text" id="tb1" />     <input type="text" id="tb2" />     <input type="button" id="bt1" value="click" /> </form> 

JavaScript (with jQuery):

$(document).ready(function() {     $('#bt1').click(function() {         $('#fr1').attr('action',                        'mailto:[email protected]?subject=' +                        $('#tb1').val() + '&body=' + $('#tb2').val());         $('#fr1').submit();     }); }); 

Notice what I'm doing here. The form itself has no action associated with it. And the submit button isn't really a submit type, it's just a button type. Using JavaScript, I'm binding to that button's click event, setting the form's action attribute, and then submitting the form.

It's working in so much as it submits the form to a mailto action (my default mail program pops up and opens a new message to the specified address), but for me (Safari, Mail.app) it's not actually specifying the Subject or Body in the resulting message.

HTML isn't really a very good medium for doing this, as I'm sure others are pointing out while I type this. It's possible that this may work in some browsers and/or some mail clients. However, it's really not even a safe assumption anymore that users will have a fat mail client these days. I can't remember the last time I opened mine. HTML's mailto is a bit of legacy functionality and, these days, it's really just as well that you perform the mail action on the server-side if possible.

like image 35
David Avatar answered Sep 22 '22 04:09

David