Post form not working

Hi,
I am not a PHP programer so I am a bit lost on this form.
I have got a contact form here which triggers a PHP function in charge of sending the email. My issue is that the message is being sent but it never displays the test.php page. What am I missing ?

Hi Corobori,

We’ll need to see the code that handles the form submission before we can help :slight_smile:

<?php
// declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = nl2br($_POST['message']);

// set a title for the message
$subject = "Message de pbagestion.ch";
$body = "De $name, Téléphone $phone,  \n\n$message";
$headers = 'From: '.$email.'' . "\r\n" .
    'Reply-To: '.$email.'' . "\r\n" .
	'Content-type: text/html; charset=utf-8' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

// put your email address here
mail("myemailhere@gmail.com", $subject, $body, $headers);
?>

Is this code from test.php, and should there be HTML after the PHP (to display a message)? Or you want it to redirect to test.php once the email is sent?

Here is how it looks like in my editor:

Ah OK, I just looked at your form again and realised that it gets submitted by AJAX, so you’ll want to change your PHP script to return some HTML to indicate success or failure of the submission:

<?php

// Set up emai vars etc..

$wasSent = mail("myemailhere@gmail.com", $subject, $body, $headers);

if ($wasSent) {
?>

<p>Thank you for contacting us. We'll be in touch soon.</p>

<?php } else { ?>

<p>Sorry, there was a problem sending your message. Please try again.</p>

<?php } ?>

Thanks fretburner for your help. I somehow oversaw the AJAX thing. Anyway issue has been fixed and form is working as expected, can’t blame anything else other than my poor, not to say inexistent, PHP’s knowledge.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.