Skip to content
Related Articles

Related Articles

How to create a text that permit to send email in HTML document when button is clicked ?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 02 Feb, 2022

In this article, we will learn How to create the text that permits sending the email in the HTML document when the button is clicked. We can simply create a form that can be used for creating the text i.e body of the message as well as it can be used for sending the email to the respective address.

The action property of the form is used to specify the URL of the document where the data is to be sent after submission of the form with the help of a button. In the action property, we can define the email of the sender using the mailto link in the form of HTML. Also, we can configure the email using some other properties in the mailto link.

Syntax:

<form  method="POST" action="mailto: name@gmail.com" 
enctype="multipart/form-data">

We can also send mail in the following ways:

  • Cc field: Cc stands for Carbon Copy. The user whose e-mail address is specified in this field will get a copy of the e-mail message. In this way, you can send a similar message to multiple users with one click. The e-mail addresses to whom the e-mail was sent will be visible to all other recipients as well. It is an optional field. You can use this field depending on your requirement.  

    Syntax:

    <form action="mailto:abc@gmail.com ? Cc=xyz@gmail.com">
      Send Email
    </form>
  • Bcc field:: Bcc stands for Blind Carbon Copy. The user whose e-mail address is specified in this field will get a copy of the e-mail message but the recipient’s e-mail address mentioned here will not be visible to other recipients. It is an optional field. You can use this field depending on your requirement.

    Syntax:

    <form action="mailto:abc@gmail.com ? Bcc=xyz@gmail.com">
      Send Email
    </form>

Let’s understand how to create a text that permits to send the email when the button is clicked using an example.

Example: Creating a button for sending an email using the action attribute of the form.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>E-mail</title>
</head>
  
<body>
    <h4>Click To Send An E-mail</h4>
    <form action="mailto: ahujaannie3@gmail.com">
        Username:<br>
        <input type="text" name="username" 
               placeholder="Enter Username"><br><br>
        Message:<br>
        <input type="textarea" name="message" 
            rows="10" cols="30" 
            placeholder="Enter your message">
        <br><br>
        <input type="submit" value="Send Email">
    </form>
</body>
  
</html>

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!