javascript - Phpmailer Script Not Executed

I am writing this code where there is 2 user type : Normal User & Admin User.

Normal User Submit Data To Admin User, Both Admin (More Then 1 Admins In database) & Normal User Should Receive Email Regarding The Submission Of Data.

The submission and retrieving of the data is working fine. But in the Email Part, I reuse the code from my registration part that works for the submission code, Result is, It does not read the $mail.

Both of my registration and submission files are in the same folder. (Path should be working fine).

The logic also seems fine. Maybe i forget or miss something ? Could use a help to check my code.

...//
if ($conn->query($sqlDeleteSelected) === TRUE)
{ 
   require_once  "../assets/inc/phpmailer/PHPMailerAutoload.php";   
   $mail = new PHPMailer(true);
try 
{
   $sqleMail = "SELECT * FROM users_details WHERE users_Admin_University_Name = '$basket_UniCourse_UniName_1'";
   $resultSqleMail = $conn->query($sqleMail);
   while($dataResultSqlMail=mysqli_fetch_assoc($resultSqleMail))
   { 
     $mail->AddAddress($dataResultSqlMail['users_Email']);
   }
   $mail->From = "myemail@gmail.com";
   $mail->FromName = "MyName";
   $mail->isHTML(true);
   $mail->Subject = 'Application Registered';
   $mail->Body = 'Congratulations!';
   $mail->Send();                                        
     if($mail->Send())
        {
           // echo "Message has been sent successfully";
              ?>
                  <script type="text/javascript">
                       alert("sucesss");
                  </script>
              <?php
        }
    else
       {
             ?>
                <script type="text/javascript">
                     alert($mail->ErrorInfo);
                </script>
             <?php
       }
}
   catch (phpmailerException $e)
     {
            echo $e->errorMessage();
     }
  catch (Exception $e)
     {
         echo $e->getMessage();
     }
}
//..

Thank You So Much.

Answer

Solution:

I'm not sure if I understand you 100% correctly but I assume that the java script "success" or the alert is not executed? This is because your if condition is not used properly. Actually you are trying to send the email twice:

 $mail->Send();                                        
     if($mail->Send())
        {...

A better way to see if the email was send successfuly is using a try&catch:

try {
    $mail->send();
    // print success message
} catch (Exception $e) {
    // print error message
}

Source