I developed a web-form for a blog, and I need to send its values to an email.
How can I send an email by using jQuery or JavaScript alone?
I developed a web-form for a blog, and I need to send its values to an email.
How can I send an email by using jQuery or JavaScript alone?
The short answer is that you can't do it using JavaScript alone. You'd need a server-side handler to connect with the SMTP server to actually send the mail. There are many simple mail scripts online, such as this one for PHP:
Using a script like that, you'd POST the contents of your web form to the script, using a function like this:
And then the script would take those values, plus a username and password for the mail server, and connect to the server to send the mail.
You can do it server-side with nodejs.
Check out the popular Nodemailer package. There are plenty of transports and plugins for integrating with services like AWS SES and SendGrid!
The following example uses SES transport (Amazon SES):
let nodemailer = require("nodemailer");
let aws = require("aws-sdk");
let transporter = nodemailer.createTransport({
SES: new aws.SES({ apiVersion: "2010-12-01" })
});
You can send mail by Jquery just follow these steps
Include this link : <script src="https://smtpjs.com/v3/smtp.js"></script>
After that use this code:
$( document ).ready(function() {
Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'them@website.com',
From : "you@isp.com",
Subject : "This is the subject",
Body : "And this is the body"}).then( message => alert(message));});