Open In App

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

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:



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.




<!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:


Article Tags :