Reputation: 159
Hello, i'm trying to create a Windows 10 App with Javascript for self education. Today i want to try, send a email with message, Name from a Contact form. I'm only beginner on Javascript. can someone write a short code with example? I have a Contact form with PHP, but how can i send a Mail with Javascript?
<form method="post" action="send.js">
<input type="text" placeholder="Name" name="name" id="name" required=" ">
<input type="email" placeholder="Email" name="email" id="email" required=" ">
<textarea placeholder="Message..." name="msg" id="msg" required=" "></textarea>
<input type="submit" value="Submit">
</form>
Thanks
Upvotes: 0
Views: 9310
Reputation: 4605
You could also use
<a href="mailto:[email protected]">Send email</a>
And that will open the default mail application on the user's device, and automatically fill in the To: field with that e-mail address.
Here is an example of how it works.
It is also possible to specify initial values for headers (e.g. subject, cc, etc.) and message body in the URL. Blanks, carriage returns, and linefeeds cannot be embedded but must be percent-encoded.
<a href="mailto:[email protected]?subject=This%20is%20the%20subject&[email protected]&body=This%20is%20the%20body">Send email</a>
Upvotes: 1
Reputation: 83
As far as I know you can't send mail with javascript. Normally you'd use javascript to send your form to your php page. You could use something like jquery and ajax the form to you php script so:
$(document).ready(function(){
$('#your-form-id').on('submit', function(){
var formData = $(this).serialize
$.ajax({
type: 'post',
url: 'your_url.php',
data: formData,
dataType: 'json',
success: function(response){
//Anything you want to do after form is submitted
}
});
});
});
This isn't tested code but I think it should be roughly right.
Upvotes: 0
Reputation: 1945
If you want to send e-mails via JavaScript, use Node.js Nodemailer. https://nodemailer.com/Nodemailer - Send e-mails with Node.JS
Upvotes: 1