0 Replies Latest reply on Aug 11, 2014 1:56 PM by thomas-shaw

    How do i change the path of data ajax false from returning to homepage, when using a PHP mail form in jquery mobile?


      I have a put a php mail form in the quote page of my mobile site. However when i send the form it returns to the route page rather than the quote page, i have used the data ajax false action as i dont want to send via ajax. i have left the thanks page blank as i want it to remain on the same page showing sent or declined message.  Can someone help please? 




      $yourEmail = "Thomas-shaw1988@hotmail.co.uk"; // the email address you wish to receive these mails through

      $yourWebsite = "www.firstcalltransport.co.uk"; // the name of your website

      $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page

      $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4

      $requiredFields = "name,email,collection,delivery,comments"; // names of the fields you'd like to be required as a minimum, separate each field with a comma



      $error_msg = array();

      $result = null;


      $requiredFields = explode(",", $requiredFields);


      function clean($data) {

        $data = trim(stripslashes(strip_tags($data)));

        return $data;


      function isBot() {

        $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");



        foreach ($bots as $bot)

        if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)

        return true;



        if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")

        return true;


        return false;




      if ($_SERVER['REQUEST_METHOD'] == "POST") {

        if (isBot() !== false)

        $error_msg[] = "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];


        // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..

        // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam

        $points = (int)0;


        foreach ($badwords as $word)

        if (

        strpos(strtolower($_POST['comments']), $word) !== false ||

        strpos(strtolower($_POST['name']), $word) !== false


        $points += 2;


        if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)

        $points += 2;

        if (isset($_POST['nojs']))

        $points += 1;

        if (preg_match("/(<.*>)/i", $_POST['comments']))

        $points += 2;

        if (strlen($_POST['name']) < 3)

        $points += 1;

        if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))

        $points += 2;

        if (preg_match("/[bcdfghjklmnpqrstvwxyz]{7,}/i", $_POST['comments']))

        $points += 1;

        // end score assignments



        foreach($requiredFields as $field) {



        if (!isset($_POST[$field]) || empty($_POST[$field]) && array_pop($error_msg) != "Please fill in all the required fields and submit again.\r\n")

        $error_msg[] = "Please fill in all the required fields and submit again.";



        if (!empty($_POST['name']) && !preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))

        $error_msg[] = "The name field must not contain special characters.\r\n";

        if (!empty($_POST['email']) && !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+ ' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))

        $error_msg[] = "That is not a valid e-mail address.\r\n";

        if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\ /?/i', $_POST['url']))

        $error_msg[] = "Invalid website url.\r\n";


        if ($error_msg == NULL && $points <= $maxPoints) {

        $subject = "Automatic Form Email";


        $message = "You received this e-mail message through your website: \n\n";

        foreach ($_POST as $key => $val) {

        if (is_array($val)) {

        foreach ($val as $subval) {

        $message .= ucwords($key) . ": " . clean($subval) . "\r\n";


        } else {

        $message .= ucwords($key) . ": " . clean($val) . "\r\n";



        $message .= "\r\n";

        $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";

        $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";

        $message .= 'Points: '.$points;


        if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {

        $headers   = "From: $yourEmail\r\n";

        } else {

        $headers   = "From: $yourWebsite <$yourEmail>\r\n";


        $headers  .= "Reply-To: {$_POST['email']}\r\n";



        if (mail($yourEmail,$subject,$message,$headers)) {

        if (!empty($thanksPage)) {

        header("Location: $thanksPage");


        } else {

        $result = 'Your mail was successfully sent.';

        $disable = true;


        } else {

        $error_msg[] = 'Your mail could not be sent this time. ['.$points.']';


        } else {

        if (empty($error_msg))

        $error_msg[] = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';



      function get_data($var) {

        if (isset($_POST[$var]))

        echo htmlspecialchars($_POST[$var]);








      <meta charset="utf-8">

      <title>Untitled Document</title>


      <link href="CSS/stylesheetnew.css" rel="stylesheet" type="text/css">

      <link href="../jquery-mobile/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css">

      <script src="../jquery-mobile/jquery-1.5.min.js" type="text/javascript"></script>

      <script src="../jquery-mobile/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>


      <style type="text/css">

        p.error, p.success {

        font-weight: bold;

        padding: 10px;

        border: 1px solid;


        p.error {

        background: #ffc0c0;

        color: #F00;


        p.success {

        background: #b3ff69;

        color: #4fa000;








      <div data-role="page" id="home">

        <div data-role="header" data-position="fixed">

         <h1>FIRSTCALL TRANSPORT</h1>


          <div data-role="navbar" data-position="fixed">


                                        <li><a href="#about">About</a></li>

                                        <li><a href="#services">Services</a></li>

                                        <li><a href="#contact">Contact</a></li>

                                        <li><a href="#quote">Quote</a></li>



        <div data-role="content"> </div>


           <div data-role="footer" data-position="fixed" > </div>





      <div data-role="page" id="quote">

        <div data-role="header" data-position="fixed">

          <h1>GET A QUOTE</h1>



        <div data-role="content">



      if (!empty($error_msg)) {

        echo '<p class="error">ERROR: '. implode("<br />", $error_msg) . "</p>";


      if ($result != NULL) {

        echo '<p class="success">'. $result . "</p>";



      <form action="<?php echo basename(__FILE__); ?>" method="post" data-ajax="false"  >


        <p><input type="hidden" name="nojs" id="nojs" /></p>



        <label for="name">Name: *</label>

        <input type="text" name="name" id="name" value="<?php get_data("name"); ?>" /><br />


        <label for="email">E-mail: *</label>

        <input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /><br />


              <label for="company">Company:</label>

        <input type="text" name="company" id="company" value="<?php get_data("company"); ?>" /><br />


        <label for="collection">Collection: *</label>

        <input type="text" name="collection" id="collection" value="<?php get_data("collection"); ?>" /><br />


          <label for="delivery">Delivery: *</label>

        <input type="text" name="delivery" id="delivery" value="<?php get_data("delivery"); ?>" /><br />


        <label for="comments">Message: *</label>

        <textarea name="comments" id="comments" rows="5" cols="20"><?php get_data("comments"); ?></textarea><br />



        <input type="submit" name="submit" id="submit" value="Send" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> />


      </form>  </div>


           <div data-role="footer" >  </div>