Note that there are some explanatory texts on larger screens.

plurals
  1. POPost form values using jquery and PHP
    primarykey
    data
    text
    <p>I'm trying to send a simple form to an email using PHP , but cannot get the actual ajax function to work.</p> <p>This is the form:</p> <pre><code>&lt;form id="quick-booking-form" method="post" action="#"&gt; &lt;input type="text" name="mail" id="mail"&gt; &lt;textarea name="message" id="message"&gt; &lt;/textarea&gt; &lt;input type="submit" value="Send the Message" id="SendTheForm"&gt; &lt;/form&gt; </code></pre> <p>This is then sent to a separate Javascript function, which holds the ajax:</p> <pre><code>$(function() { //alert("page loaded"); $('#quick-booking-form').submit(function(event) { event.preventDefault(); alert("Start of function"); var mail = $("#mail").val(); var message = $("#message").val(); alert("Mail: " + mail + " Message: " + message); $.ajax({ type: "POST", url:"process.php", data:{ "mail": mail, "message": message, }, dataType: "text" }).success(function(result){ alert(result); //next line: end of function }) ; //next line: end of ajax }); //next line: end of script }); </code></pre> <p>which should send the data to this PHP file (process.php):</p> <pre><code>$msg = $_POST['message']; $UserName = $_POST['mail']; $contact = "Booking Manager"; $reply = "web-bookings@thesite.net"; //Subject is always... $subject = "A message from ".$UserName; $from = $reply; //test data //$contactDetails = "test@test.net"; // send message $message = "Message reads: ".$msg; //$to = "notify@test.com"; $to = $_POST['mail']; //$headers = "From: " . $contact."\r\n"."Reply-To:".$reply; $headers = "From: " . $contact; mail($to, $subject, $message, $headers); echo "Mail Sent."; </code></pre> <p>What should happen is that the form is submitted. It then gets validated (code omitted) in validate.js . If it passes, the form data is sent to process.php. This in turn sends a notification message to notify@test.com .</p> <p>What currently happens is that the <code>alert("Start of Function")</code> fires, and so does the alert showing the correct values.</p> <p>And this is as far as it gets. The mail function does not seem to fire, and the last alert does not show either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload