title: ajax wordpress contact form
body: <p><strong>UPDATE:</strong></p>
  
  <pre><code>&lt;form method="post" id="formApply"  action="&lt;?php bloginfo('template_url');?&gt;/inc/sendContact.php" name="applyForm"&gt;
      &lt;div id="col1"&gt;
          &lt;fieldset class="col-1"&gt;
              &lt;div class="white info-line"&gt;Want to know more? Drop us a line and we'll get right back to you.&lt;/div&gt;
              &lt;label class="white text-label name" for="fname"&gt;Name:&lt;/label&gt;&lt;input type="text" name="fname" id="fname" tabindex="1" /&gt;
              &lt;div class="clear"&gt;&lt;/div&gt;
              &lt;label class="white text-label email" for="email"&gt;Email:&lt;/label&gt;&lt;input type="email" class="lower" name="email" id="email"  tabindex="2"/&gt;
              &lt;div class="clear"&gt;&lt;/div&gt;
              &lt;label class="white text-label phone" for="phone"&gt;Phone:&lt;/label&gt;&lt;input type="tel" name="phone" id="phone" tabindex="3" maxlength="10"/&gt;
              &lt;div class="white text-label checker-title" id="checkererror"&gt;I am interested in:&lt;/div&gt;
              &lt;input type="checkbox" id="checkbox-2-1" class="regular-checkbox big-checkbox" name="checker[]" value="Office Space" /&gt;&lt;label for="checkbox-2-1"&gt;&lt;/label&gt;&lt;div class="white text-label checker"&gt;Office Space&lt;/div&gt;
              &lt;input type="checkbox" id="checkbox-2-2" class="regular-checkbox big-checkbox" name="checker[]" value="Designated Workspace" /&gt;&lt;label for="checkbox-2-2"&gt;&lt;/label&gt;&lt;div class="white text-label checker"&gt;Designated Workspace&lt;/div&gt;
              &lt;input type="checkbox" id="checkbox-2-3" class="regular-checkbox big-checkbox" name="checker[]" value="Shared Space" /&gt;&lt;label for="checkbox-2-3"&gt;&lt;/label&gt;&lt;div class="white text-label checker"&gt;Shared Space&lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;
      &lt;div id="col2"&gt;
          &lt;fieldset class="col-2"&gt;
              &lt;label class="white text-label note-label" for="notes"&gt;Notes:&lt;/label&gt;&lt;br/&gt;
              &lt;textarea name="notes" id="notes" rows="10" cols="30" class="requiredField" tabindex="4"&gt;&lt;/textarea&gt;
              &lt;input type="hidden" name="submitted" id="submitted" class="submitted" value="true" /&gt;&lt;button id="submit" type="submit"&gt;Submit Application&lt;/button&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So i changed the form to a php on action - the email sends now fine - but it takes the user to the blank sendContact.php.</p>
  
  <p>Is there a way of redirecting them back to the site? or doing this via ajax?</p>
  
  <p>i tried a few ways in ajax and it wasnt sending the email</p>
  
  <p>Thanks!</p>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>require_once 'lib/swift_required.php';
  
  
  $transport = Swift_MailTransport::newInstance();
  
  $mailer = Swift_Mailer::newInstance($transport);
  
  $name = Trim(stripslashes($_POST['fname']));
  $email = Trim(stripslashes($_POST['email']));
  $phone = Trim(stripslashes($_POST['phone']));
  $notes  = Trim(stripslashes($_POST['notes']));
  $checkbox = $_POST['checker'];
  
  
  $message = Swift_Message::newInstance()
    -&gt;setFrom(array('From_Email' =&gt; 'My Website'))
    -&gt;setSubject('[My_Subject from '.$name.']')
    -&gt;setTo(array('My_Email'))
    -&gt;setBody(
  '&lt;html&gt;'.
  '&lt;head&gt;&lt;/head&gt;'.
  '&lt;body&gt;'.
  '&lt;strong&gt;Name:&lt;/strong&gt;&lt;br /&gt;'.
  $title.' '.$name.'&lt;br /&gt;&lt;br /&gt;'.
  '&lt;strong&gt;Email Address:&lt;/strong&gt;&lt;br /&gt;'.
  $email.'&lt;br /&gt;&lt;br /&gt;'.
  '&lt;strong&gt;Phone Number:&lt;/strong&gt;&lt;br /&gt;'.
  $phone.'&lt;br /&gt;&lt;br /&gt;'.
  '&lt;strong&gt;Interested in:&lt;/strong&gt;&lt;br /&gt;'.
  implode('&lt;br /&gt;', $checkbox).'&lt;br /&gt;&lt;br /&gt;'.
  '&lt;strong&gt;Message:&lt;/strong&gt;&lt;br /&gt;'.
  $notes.'&lt;br /&gt;&lt;br /&gt;'.
  '&lt;/body&gt;'.
  '&lt;/html&gt;',
  'text/html' );
  $result = $mailer-&gt;send($message);  
  </code></pre>