I have been researching for that problem for many hours, and didn't find anything.
So, I have a static html page and button inside it, like that:
<body>
<button id="0">SEND EMAIL TO my#email.com</button>
</body>
And if I press this button, message "Hello" will be sent to my#email.com from my2#email.com
Is it possible to do that thing using only html or javascript or jquery (because i know only that languages)?
There are three ways to do it
Harder Way
You have to implement server code to send a mail
Less Harder Way
You have to use mailgun or sendgrid rest api to send a mail using javascript.
Simpler Way
You have to use https://formspree.io/ to send a mail from your HTML.
Update:
Recently I found a way to send email using Google script. You don't need the backend. Explained here https://github.com/dwyl/html-form-send-email-via-google-script-without-server
You can use :
<body>
<a href = 'mailto:my#email?body="Yourbody"&subject="a subject".com'>SEND EMAIL TO my#email.com</a>
</body>
It will open a mail manager (outlook, gmail, ...) to send a new mail. You can describe the body and the subject inside the link
Otherwise you can send data to PHP with a form tag and send an email this PHP.
Directly sending mail from static web page is not possible.
You can use third party service, i am using service from formspree and it is working fine for me.
All you have to do is create your account in formspree, verify gmail address and use below snippet in your HTML page.
<form action="http://formspree.io/your#email.com" method="POST">
<input type="email" name="_replyto">
<textarea name="body">
</textarea>
<input type="submit" value="Send">
</form>
formspree is self explainatory.
Related
Let's say I have a website where there is a button. When you click on this button the website will send the current page html (either as the body of an email or as an attachment ex: index.html) to a specific email address. Is this possible? If so, how? (I want to do it in either with html tags or javascript).
It's like sending a form but instead you send an html page.
What you're describing looks to be a use case for NodeMailer. Assumption here is that you're using Node.js as your backend. There are many options for other languages pypi-mailer being a common option for python.
Regardless, you would need to have a html form (or a default option of email)
<form action="/sendMail">
<label for="email">Email: </label><br>
<input type="text" id="email" name="email" value="Enter your email"><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be send to an endpoint /sendMail".</p>
Then you would need Javascript on the front-end to actually get the object. I believe this answer is what you're looking for here.
This link explains how to actually use nodemailer to send an email.
Hope this helps!
I have HTML form with a textbox where user enter his email - let say to register for a newsletter and a button to join.
When clicking the button I'd like to send myself an email with a constant subject like: 'a new user joined your newsletter' and in the body of the email have the text entered by the user.
So with PHP and Javascript code its possible - i'm looking for a pure html code that does the same (in my index.html file)
using <a href: mailto...> or <form action=mailto:... method=post> or <button onclick:mailto...> opens my mail application :(
Is there a way to send that email in the background (without opening the mail application) with the data from textbox in the email body?
if Yes to Q.1 then is there a way to add a fixed subject
No, there is no way you can send email using pure html. Email is sent over SMTP protocol. A browser operates in HTTP protocol. So it's not possible to send email even using pure javascript. Only server can send data using SMTP protocol.
No because you can not send an E-Mail without using an SMTP server. This server must be contacted by PHP or another server-side script (server must receive a form request and process it). You can not contact a SMTP server via pure HTML (that would be really insecure btw).
Regarding mailto: This only works if your clients have installed a mail client on their local machine. This mail client must be properly configured in order to - guess what - contact an SMTP server in order to send the mail.
However it is possible passing a subject via mailto:
https://css-tricks.com/snippets/html/mailto-links/
I am trying to write a function to send an email when the user clicks on "submit".
Any ideas how to do so?
Lets say I have a
<script>
function mail()
{
var players = document.getElementById('players').value;
var slots = document.getElementById('slots').value;
}
</script>
and I want to generate an mail with those three vars.
Thanks all :)!
You can't send emails from (client-side) JavaScript alone. What you can do is write a server-side program that takes inputs (maybe as a POST or XHR request), creates an email out of it and sends it.
You may need to post the details to a server which would mail or you can use the mailto function to invoke default mail client on the client's computer like
<form action="mailto:sample#stackoverflow.com" method="post" enctype="text/plain" >
variable1:<input type="text" name="v1">
variable2:<input type="text" name="v2">
<input type="submit" name="submit" value="Submit">
</form>
You will have to use it in combination of a server side language and javascript. You can use javascript to write the "interface" to the mail function. But you will need to look into php or another language.
A php example of this is
You can find more details on the manual here http://us.php.net/manual/en/book.mail.php
pinehead.tv fighting for smarter newbies
"You may need to post the details to a server which would mail or you can use the mailto function to invoke default mail client on the client's computer like
variable1:
variable2:
"
This answer above will not work for people who do not have a mail client installed on their os. the mailto feature in html will open up the users "outlook" type program to send the mail.
I am developing a static website where in i want to send an email when HTML "Send Button" is clicked. IF it is possible it would be nice if u can share the code
Thanks
short answer: No!
Long answer:
No, you can't send emails from static pages even using javascript. What you can do is to use ajax to send email from your html form.
It is possible ;-)
<input type="submit" value="Send" onclick="window.location ='mailto:email#address.com' "/>
In short: Forget it.
If you want to send email with the slightest resemblance of reliability, use a server side process. If you want to use JavaScript then you can use Ajax to pass the data to that server side process and/or SSJS.
It is not possible to send email from Javascript, you'll need to write a page in a language like PHP to receive the POST data and use the mail() command there.
I'm sorry but just with a static website you can't do it. One imaginable possibility would be make a very complex javascript code to access one webmail account you have, login there and send the email using this account to you. It's theoretically possible, but I've never seen something like it...
Am very New to Web Page Development.
In my website i have the help page like Name, Email ID, Contact No, Comment and Submit Button Suppose i entered the data in the help page , then i press submit button means that entered data's should sent to the email account
For Example
Help Page
Name - Raja
Email - raja#gmail.com
Contact - 98763214
Comments - Good web page
Then I pressed Send button means, the above entered data should send to this email account
support#it.com with the same format.
Need Code Help or Script Help
use FormMail
you should set these variables in formmail.pl
#referers = ('yourdomain.com','ip_number');
look at this
and
#recipients = ('^support\#it\.com');
look at this
and
$mailprog = '/usr/lib/sendmail -i -t';
which is the path of sendmail in your system. if you're not sure where is your sendmail path, use the following command at your unix prompt:
which sendmail
This will tell you where sendmail is on your system. If it says it could not find it, just ask your system administrator.
after configured formmail.pl, put it in cgi-bin folder.
here is an example of a form using formmail.pl ( recipient field is required )
<form name="myform" action="http://yourdomain.com/cgi-bin/test.pl" method="GET">
<input type=hidden name="recipient" value="support#it.com">
<input type=textarea name="mytext"/>
<input type="submit" />
</form>
for more information about how to use formmail, go here.
Like Jørn Schou-Rode said, you really need to use a server-side programming language to catch and process the form data. The options are numerous - PHP, ASP, .NET, ColdFusion, Java, Ruby... the list goes on. See http://en.wikipedia.org/wiki/Server-side_scripting as a starting point.
I remember starting out in web development and wanting to do the same thing but you really are now getting into more advanced areas of development (beyond simple client-side HTML/CSS/JavaScript coding).