简体   繁体   中英

Can I Send an Email using ONLY Javascript Without Having to Click The Send Button on the Email Client?

I created a form in HTML and when the submit button is clicked the onclick event calls the following function:

function ProcessSubmition(){

   var stringEmailBody=BuildEmailBody();

   var stringTo=document.getElementById("SubmittersEmail").value;

   var stringSubject = "My Subject Text";

   window.location.href = "mailto:"+stringTo+"?subject="+stringSubject+"&body="+stringEmailBody;

}

There are two requirements to my project:

  1. No PHP is allowed on our server.
  2. The person filling out the form must not be able to edit the data which contains a calculate price.

The Problem:

When the function launches, the mail client window appears and displays the message constructed by the function and the user must click the "Send" button in the mail client window.
Unfortunately before the user clicks send, they can simply change the calculated price to a lower dollar amount which obviously is unacceptable.

Is there any way to hide the mail client window and auto-sent? Alternately is there any other method I could use to solve the problem?

Thank you for any help you can give me.

Short answer: No

The JavaScript code that runs in the context of a browser is client-side code that can be manipulated by the end-users. For that reason, you should never rely on client-side code to perform any sensitive operations.

Basically, you will need some server-side support to do what you are tyring to achieve or it will never be secure. Now, if it's dangerous for you that the users can tamper with your code, it would also be dangerous for them if your code could perform tasks such as sending e-mails on their behalf without any form of approval.

Even if you could talk directly to the mail client like you asked and make the email being sent automatically, there's nothing that would prevent users from editing the JavaScript source that generates the message and change the message content.

Alternative? If you will never be able to use any server-side technology, Maybe you could simply send the form details by e-mail and do the pricing calculations in another process afterwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM