Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I try to send message by filling the form in my webpage, Mail app opens simultaneously. How to avoid this?

What I have tried:

function send() {
    var link = 'mailto:abhinavkishorem9@gmail.com?subject=Message from '
             +document.getElementById('message').value
             +'&body='+document.getElementById('message').value;
 
}

<div id="form-container">
          <h3 style="font-family: Anton, sans-serif;font-style: italic;">Contact Form</h3>
          <form action="mailto:abhinavkishorem9@gmail.com" method="post" enctype="text/plain">
            <label for="name">Name</label> <input type="text" id="name"> <label for="email">Email</label> <input type="text" id="email"> <label for="subject">Subject</label> <input type="text" id="subject"> <label for="message">Message</label> 
            <textarea id="message"style="font-family: Anton, sans-serif;font-style: italic;">Write your message here..</textarea> <button class="rounded">Send Message</button>
          </form>
        </div>
Posted
Updated 2-Oct-22 21:42pm
v2

You can't do it in JS without an email app on the client server - you need to send the request data to the backend code (C#, VB, PHP, whatever) and use the server email facilities.

Think about it: if you could send an email from JS, you would be using the client email address and password (which you don't know), the client email server (which you don't know) and if it did work then malicious code could do it as well - using your personal or corporate email id to spam or phish contacts. That would be a bad thing as everybody would - rightly - assume the mail came from you or your company.
 
Share this answer
 
Comments
Abhinav Kishore M 3-Oct-22 3:31am    
could u explain this with an example, through code?
OriginalGriff 3-Oct-22 4:08am    
No - I have no idea what your backend code is, or how it works!
HTML and JS alone won't do it, you'll need a server-side language like PHP to send emails. It's probably best to install a framework and go from there (like Laravel), otherwise, look up the mail() function or use PhpMailer, SwiftMailer, etc.
 
Share this answer
 
Comments
Abhinav Kishore M 3-Oct-22 6:47am    
ok thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900