Button onclick send mail

Here is an example of how you can send an email using a button click in HTML, CSS, and JavaScript:

HTML:

<button id="send-email-btn">Send Email</button>

CSS:

#send-email-btn {
  background-color: #4CAF50;
  color: #fff;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

JavaScript:

const sendEmailBtn = document.getElementById('send-email-btn');

sendEmailBtn.addEventListener('click', () => {
  const email = '[email protected]'; // replace with recipient's email
  const subject = 'Test Email'; // replace with subject
  const body = 'This is a test email sent using JavaScript!'; // replace with body

  const mailto = `mailto:${email}?subject=${subject}&body=${body}`;

  window.location.href = mailto;
});

In this example, we first get a reference to the button element using document.getElementById. We then add an event listener to the button using addEventListener, which listens for a click event.

When the button is clicked, the event listener function is called, which constructs a mailto link using the recipient's email, subject, and body. The mailto link is then used to open the default email client on the user's device.

Note that this code assumes that the user has a default email client installed on their device. If the user does not have a default email client, the link will not work.

You can also use a library like jQuery to simplify the process:

$('#send-email-btn').on('click', function() {
  const email = '[email protected]'; // replace with recipient's email
  const subject = 'Test Email'; // replace with subject
  const body = 'This is a test email sent using JavaScript!'; // replace with body

  window.location.href = `mailto:${email}?subject=${subject}&body=${body}`;
});