title: How to send auto-respond email with PHPMailer
body: <p>I am trying to build an inquiry form and send the data to my email using PHPMailer. I am receiving the data which is submitted through the form but I am not able to send a confirmation to the customer who filled the form. So far this is my form:</p>
  
  <pre><code>&lt;form class="myForm" action="" id="iForm" method="POST"&gt;
          &lt;input type="text"  id="Name" placeholder="Name" required&gt; 
          &lt;input type="email" id="Email" placeholder="Email" required&gt;
          &lt;input type="tel"   id="Phone" placeholder="Phone Number" required&gt;
          &lt;input type="text"  id="Date" placeholder="Schedule a call" required&gt;
          &lt;textarea id="Message" rows="5" placeholder="Your Message"  required&gt;&lt;/textarea&gt;
          &lt;div class="form-group"&gt;
               &lt;button type="submit" class="btn cbtn"&gt;SUBMIT&lt;/button&gt;
          &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Passing the data from the submitted form </p>
  
  <pre><code>$("#iForm").on('submit', function(e) {
  e.preventDefault();
  var data = {
      name: $("#Name").val(),
      email: $("#Email").val(),
      phone: $("#Phone").val(),
      date: $("#Date").val(),
      message: $("#Message").val()
  };
  
  if ( isValidEmail(data['email']) &amp;&amp; (data['name'].length &gt; 1) &amp;&amp; (data['date'].length &gt; 1) &amp;&amp; (data['message'].length &gt; 1) &amp;&amp; isValidPhoneNumber(data['phone']) ) {
      $.ajax({
          type: "POST",
          url: "php/appointment.php",
          data: data,
          success: function() {
              $('.success.df').delay(500).fadeIn(1000);
              $('.failed.df').fadeOut(500);
          }
      });
  } else {
      $('.failed.df').delay(500).fadeIn(1000);
      $('.success.df').fadeOut(500);
  }
  
  return false;
  });
  </code></pre>
  
  <p>Checking for valid email address</p>
  
  <pre><code>function isValidEmail(emailAddress) {
      var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
      return pattern.test(emailAddress);
  }
  </code></pre>
  
  <p>Checking for a valid phone number</p>
  
  <pre><code>function isValidPhoneNumber(phoneNumber) {
      return phoneNumber.match(/[0-9-()+]{3,20}/);
  }
  </code></pre>
  
  <p>This is the code which I am using from PHPMailer:</p>
  
  <pre><code>$_name      = $_REQUEST['name'];
  $_email     = $_REQUEST['email'];
  $_phone     = $_REQUEST['phone'];
  $_date      = $_REQUEST['date'];
  $_message   = $_REQUEST['message'];
  
  $mail = new PHPMailer(true);
  $mail-&gt;IsSMTP();
  $mail-&gt;CharSet    = 'UTF-8';
  $mail-&gt;SMTPDebug  = 0;
  $mail-&gt;SMTPAuth   = TRUE;
  $mail-&gt;SMTPSecure = "tls";
  $mail-&gt;Port       = 587;
  $mail-&gt;Username   = "office@myhost.co.uk";
  $mail-&gt;Password   = "********";
  $mail-&gt;Host       = "myhost.co.uk";
  
  $mail-&gt;setFrom('office@myhost.co.uk', 'Alex');
  $mail-&gt;addAddress('me@gmail.com', 'Alex');
  
  $mail-&gt;isHTML(true);
  $mail-&gt;Subject     = 'New inquiry from CC';
  $mail-&gt;Body        = &lt;&lt;&lt;EOD
       &lt;strong&gt;Name:&lt;/strong&gt; $_name &lt;br&gt;
       &lt;strong&gt;Email:&lt;/strong&gt; &lt;a href="mailto:$_email?subject=feedback" "email me"&gt;$_email&lt;/a&gt; &lt;br&gt; &lt;br&gt;
       &lt;strong&gt;Phone:&lt;/strong&gt; $_phone &lt;br&gt;
       &lt;strong&gt;Booking Date:&lt;/strong&gt; $_date &lt;br&gt;
       &lt;strong&gt;Message:&lt;/strong&gt; $_message &lt;br&gt;
  </code></pre>
  
  <p>I've tried using this, making another instance of PHPMailer and Send the email to the customer with the email they provided.</p>
  
  <pre><code>if($mail-&gt;Send()) {
  $autoRespond = new PHPMailer();
  $autoRespond-&gt;setFrom('office@myhost.co.uk', 'Alex');
  $autoRespond-&gt;AddAddress($_email); 
  $autoRespond-&gt;Subject = "Autorepsonse: We received your submission"; 
  $autoRespond-&gt;Body = "We received your submission. We will contact you";
  
  $autoRespond-&gt;Send(); 
  }
  </code></pre>
  
  <p>I've tried a few online "solutions" to this with no success. Any ideas ?</p>