Can we send mail by click on html button

Yes, it is possible to send mail by clicking on an HTML button. This can be achieved using JavaScript and a mail service API. Here's a general outline of the process:

  1. Create an HTML button:
    <button id="send-mail-btn">Send Mail</button>
  2. Add a JavaScript event listener to the button:
    document.getElementById('send-mail-btn').addEventListener('click', sendMail);
  3. Define the sendMail function:
    
    function sendMail() {
    // Get the mail service API endpoint and credentials
    const apiUrl = 'https://your-mail-service-api.com/api/send-mail';
    const apiKey = 'your-api-key';
    const apiSecret = 'your-api-secret';

// Get the form data (e.g. recipient's email, subject, body) const recipientEmail = document.getElementById('recipient-email').value; const subject = document.getElementById('subject').value; const body = document.getElementById('body').value;

// Create a JSON payload for the API request const payload = { 'recipient_email': recipientEmail, 'subject': subject, 'body': body };

// Make the API request using JavaScript's fetch API fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': Bearer ${apiKey} }, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); }


4. In the `sendMail` function, you'll need to replace the placeholders (`your-mail-service-api.com`, `your-api-key`, `your-api-secret`) with the actual values for your mail service API.

Some popular mail service APIs that you can use include:

* Mailgun: https://mailgun.com/
* Sendgrid: https://sendgrid.com/
* Amazon SES: https://aws.amazon.com/ses/

Keep in mind that you'll need to set up an account with the mail service provider and obtain an API key and secret to use their API.

Also, note that this is just a basic example, and you may need to add additional error handling and validation to your code depending on your specific use case.