Jump to content

muzaffar527

New Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About muzaffar527

  • Rank
    Newbie
  1. , 02:03 PM //My contact.php <!DOCTYPE html> <html> <body> <div class="col-sm-6"> <form onsubmit="return false"> <div class="form-group"> <label for="cname" class="control-label">Full Name:</label> <input type="text" class="form-control" name="cname" id="cname"> </div> <div class="form-group"> <label for="mob" class="control-label">Phone Number:</label> <input type="text" class="form-control" name="mob" id="mob"> </div> <div class="form-group"> <label for="mail" class="control-label">Email Address:</label> <input type="email" class="form-control" name="mail" id="mail"> </div> <div class="form-group"> <label for="msg" class="control-label">Message:</label> <textarea class="form-control" rows="4" name="msg" id="msg" style="resize:none"></textarea> </div> <div id="sendmsg"> </div> <button type="submit" name="sendemail" id="sendemail" class="btn btn-success">Send Message</button> </form> </div> <script src="../res/js/jquery.min.js"></script> <script src="../res/js/bootstrap.min.js"></script> <script> $(function(){ $("#sendemail").click(function(){ var err = reqfield_val(['cname', 'mob', 'mail', 'msg']); if(err == 0){ $.ajax({ type: 'post', data: $('form').serialize() }); <?php require_once('../res/php/code.php'); $res = sendemailfn(); // I want to use the function return value here ?> $("#sendmsg").text('<?=$res?>').css("opacity",'1'); } }); }); </script> </body> </html> //mail function code in code.php file <?php function sendemailfn() { if($_POST) // to prevent form submission on page reload (& on not using this condition function is returning the value) { $res = ""; $cname = $_POST['cname']; $email_from = $_POST['mail']; $mobile = $_POST['mob']; $msg = $_POST['msg']; $to = 'muzaffar527@gmail.com'; $body = 'Name'.$cname. '\nEmail'.$email_from. '\nMobile'.$mobile. '\nMessage'.$msg; $subject = 'Enquiry from www.zuhaconsultants.com'; $headers = 'From: '.$email_from."\r\n" . 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $mail_sent = mail($to, $subject, $body, $headers); if($mail_sent == true) $res = "Thank you for contacting us. We will be in touch with you very soon."; else $res = "Seems Some Error Occured."; return $res; // this value is not returned to contact.php page // if the about condition if($_POST) is not given then it is returning the value // if it is not given the page is submitting the form on page reload } } ?> Please help me get the return value $res... in the same way please note that the form should not be submitted on page reload Thanking you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.