diphan-source/script-email

Ajax post email

kallyas opened this issue · 0 comments

<script>
  $(document).ready(function () {
    $("#contact-form").submit(function (e) {
      e.preventDefault(); // Prevent the default form submission

      // Serialize the form data
      var formData = $(this).serialize();

      // Send an AJAX request to the server-side script
      $.ajax({
        type: "POST",
        url: "your-email-endpoint.php", // Replace with the actual URL of your server-side script
        data: formData,
        success: function (response) {
          // Handle the response from the server (e.g., display a success message)
          alert("Message sent successfully!");
        },
        error: function (error) {
          // Handle errors (e.g., display an error message)
          alert("An error occurred while sending the message.");
        },
      });
    });
  });
</script>

Requires JQUERY