javascript – PHP isset Form Submit and jQuery on Submit Function conflict-ThrowExceptions

Exception or error:

I need to do this on one page as i am using phpmailer file upload,

The form value are added to the google sheets but the phpmailer stopped working, when i remove this script, then the mailer works.

$(function() {
  $('#frm_details').on('submit', function(e) {
    $('.main-form #warranty-claim').fadeOut('slow');
      url: "",
      type: "GET",
      data: $(this).serialize(),
      success: function(data) {
      error: function(data) {
        console.log('there is an error');

<script src=""></script>
<form id="frm_details" method="post" enctype="multipart/form-data">
  input type="hidden" name="MAX_FILE_SIZE" value="10000000">
  <input name="userfile[]" type="file" multiple="multiple" id="imageinput" class="form-control-file">
  <input type="submit" name="submit" value="Claim" class="w-100 h-100 form-control text-uppercase text-center d-block mx-auto">

Here’s my mailer

    use PHPMailer\PHPMailer\PHPMailer;
    if (isset($_POST['submit'])) {
if (array_key_exists('userfile', $_FILES)) {
            require 'vendor/autoload.php';
            // Create a message
            $mail   = new PHPMailer;
            $mail->setFrom('', 'John Doe');
            $mail->addAddress('', 'Me Myself');
            $mail->Subject = $ordernumber . ' - Warranty';
            $mail->Body .= '<p style="letter-spacing: 1px;margin-bottom: 10px;">Hi,</p>';
            $mail->Body .= '<p style="letter-spacing: 1px;margin-bottom: 10px;">A warranty claim has been submitted. Please look into this.</p>';

            //Attach multiple files one by one
            for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
                $uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct]));
                $filename   = $_FILES['userfile']['name'][$ct];
                if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
                    $mail->addAttachment($uploadfile, $filename);
                else {
                    $msg .= 'Failed to move file to ' . $uploadfile;

            if (!$mail->send()) {
                $msg .= "Mailer Error: " . $mail->ErrorInfo;
            else {
                $msg .= "Message sent!";

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *