title: Different behaviors on success/fail on PHPMailer
body: <p>I have a PHPMailer form and I am using .ajax using this SO answer <a href="https://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php">jquery-ajax-post-example-with-php</a></p>
  
  <p>It is successfully sending or not sending, so I know the Mailer and captcha are working. Now, if I could get different behaviors for success and fail, that would be great, but I am not getting this right somehow. </p>
  
  <p><strong>PREFERRED BEHAVIORS</strong></p>
  
  <p>SUCCESS --> reload screen and show bootstrap modal with success msg</p>
  
  <p>FAIL --> reload screen and show bootstrap modal with fail msg</p>
  
  <p>I have a lot of code so, Think of the modals as vanilla as possible, and the PHPMailer is, in fact, sending as well. The problem I am having should be in the code below, but if you have to have something else, just ask. Trying to keep the question as decluttered as possible</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
              var request;
  
              $("#contactForm").submit(function(event){
                  event.preventDefault();
  
                  // Abort any pending request
                  if (request) {
                      request.abort();
                  }
  
                  // setup some local variables
                  var $form = $(this);
  
                  // Let's select and cache all the fields
                  var $inputs = $form.find("input, select, button, textarea");
  
                  // Serialize the data in the form
                  var serializedData = $form.serialize();
  
                  // Let's disable the inputs for the duration of the Ajax request.
                  // Note: we disable elements AFTER the form data has been serialized.
                  // Disabled form elements will not be serialized.
                  $inputs.prop("disabled", true);
  
                  request = $.ajax({
                      url: "processLogin.php",
                      type: "post",
                      data: serializedData
                  });
  
                  // Callback handler that will be called on success
                  request.done(function (response, textStatus, jqXHR){
                      if (response == true ) {
                          top.location.reload();
                          // top.location.href="/";
                          // $('#successEmail').modal('show');
                      } else {
                          // top.location.reload();
                          $('#failEmail').modal('show');
                      }
                  });
  
                  // Callback handler that will be called on failure
                  request.fail(function (jqXHR, textStatus, errorThrown){
                      // Log the error to the console
                      // console.error(
                      //     "The following error occurred: "+
                      //     textStatus, errorThrown
                      // );
                      // top.location.reload();
                  });
  
                  // Callback handler that will be called regardless
                  // if the request failed or succeeded
                  request.always(function () {
                      // Reenable the inputs
                      $inputs.prop("disabled", false);
                  });
  
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>PHPMailer Form</p>
  
  <pre><code>&lt;?php
      session_start();
  ?&gt;
  &lt;?php
      /**
      * This example shows how to handle a simple contact form.
      */
      $msg = '';
  
  
      use PHPMailer\PHPMailer\PHPMailer;
  
      require './mail/PHPMailer.php';
      require './mail/Exception.php';
      require './mail/SMTP.php';
      require './mail/PHPMailerAutoload.php';
  
      include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
  
      $securimage = new Securimage();
  
      //Don't run this unless we're handling a form submission
      if (array_key_exists('email', $_POST)) {
          date_default_timezone_set('Etc/UTC');
  
          //Create a new PHPMailer instance
          $mail = new PHPMailer;
  
          $mail-&gt;SMTPDebug = 0;                                 
          $mail-&gt;isSMTP();    
          $mail-&gt;Host = 'smtp.live.com';                 
          $mail-&gt;SMTPAuth = true;     
          $mail-&gt;Username = 'email@outlook.com';       
          $mail-&gt;Password = 'password';                    
          $mail-&gt;SMTPSecure = 'tls';                   
          $mail-&gt;Port = 587;        
  
          $mail-&gt;setFrom('email@outlook.com', 'Mailer');
          $mail-&gt;addAddress('email@outlook.com', 'First Last');
  
  
          $email = isset($_POST['email']) ? $_POST['email'] : null;
          $name = isset($_POST['name']) ? $_POST['name'] : null;
          $phone = isset($_POST['phone']) ? $_POST['phone'] : null;
          $message = isset($_POST['message']) ? $_POST['message'] : null;
  
  
          if ($mail-&gt;addReplyTo($_POST['email'], $_POST['name'])) {
              $mail-&gt;Subject = 'Contact request';
              $mail-&gt;isHTML(true);
              $mail-&gt;Body = &lt;&lt;&lt;EOT
      &lt;div style="width:100%"&gt;
      &lt;div&gt;&lt;label style="color: #044F69; font-weight:bold"&gt;Email:&lt;/label&gt; &lt;span&gt;{$_POST['email']}&lt;/span&gt;&lt;/div&gt;
      &lt;div&gt;&lt;label style="color: #044F69; font-weight:bold"&gt;Name:&lt;/label&gt; &lt;span&gt;{$_POST['name']}&lt;/span&gt;&lt;/div&gt;
      &lt;div&gt;&lt;label style="color: #044F69; font-weight:bold"&gt;Phone:&lt;/label&gt; &lt;span&gt;{$_POST['phone']}&lt;/span&gt;&lt;/div&gt;
      &lt;div&gt;&lt;label style="color: #044F69; font-weight:bold"&gt;Message:&lt;/label&gt; &lt;span&gt;{$_POST['message']}&lt;/span&gt;&lt;/div&gt;
      &lt;/div&gt;
      EOT;
  
              if ($securimage-&gt;check($_POST['captcha_code']) == false) {
                  // echo "&lt;meta http-equiv='refresh' content='0'&gt;";
                  exit;
              }
  
              //Send the message, check for errors
              if (!$mail-&gt;send()) {
                  $msg = 'Sorry, something went wrong. Please try again later.';
              } else {
                  header("Location: /");
                  exit;
              }
          } else {
              $msg = 'Invalid email address, message ignored.';
          }
      }
      ?&gt;
  </code></pre>
  
  <p>P.S. The code as I have it (See above), shows the fail modal and no reload regardless of whether it passes or fail.</p>
  
  <p>Thanks in advance!</p>