Perform Post Method On Current Page January 22, 2024 Post a Comment I have this form where I'm sending a mail (via Post method) : Solution 1: Do you know about Ajax and jQuery? Read more, here.Your ajax call can look like this. $.ajax({ url: "yourApplication/methodWhichSendsEmail", type: "post", data:JSON.stringify({ to : $to, subject: $subject, message: $message, headers: $headers }) }).done(function() { //Whatever you want to do once the request is succeed. As you don't want to reload. i.e. alert("Email Sent"); }); CopySolution 2: Either by AJAX or you can do the following: You specify action="" in the <form>You include the code from sendmail.php to index.php (or whatever your homepage is)Solution 3: You need to set your form action empty.Baca JugaExceeded Maximum Stack Depth In A Custom Function For Google SheetsSymfony 1.4: How I Can Retrieve The Selected Value With Ajax's Function In Select Dependent?Jquery / Ajax Form - Serverside Php But Get Cross Domain WarningThen in PHP code you need to check if form is posted or not. SO need to check it first by php function isset then you can do whatever you want, This will only send email if a form is postedif(isset ($_POST['send']) && $_POST['send'] == 'SEND'){ $to = 'queries@mydomain.com'; $subject = $_POST['subject']; $message = $_POST['message']; $headers = "From: ".$_POST['sender_name']." <".$_POST['sender_email'].">\r\n"; $headers = "Reply-To: ".$_POST['sender_email']."\r\n"; $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } Copy Share You may like these postsWhy Doesn't Browser Parse The JS Code In The File Loaded By AJAX?Using Javascript And Php Together To ValidateSetting A Cookie With Php Within JS Gives Me An Error On Line 29, Returning A Variable From PHP Code?Wordpress Geocoding Using Direction Or A Map Post a Comment for "Perform Post Method On Current Page"
Post a Comment for "Perform Post Method On Current Page"