Contact form contact.php not working properly

Hi,

I got a template with Contact.html page. I create a contact.php for the contact form on the page.
Kindly check my Contact.php for the given contact form on Contact.html page and let me know what changes in code are required to make it working.

for website http://www.klixters.xyz/contact.html

Regards

You can start with getting rid of the duplicate opening form tag.

not working properly

What does that mean? You do realize we cannot see the Php code right? Post it here.

1 Like

HI,
What does that mean? - I get an error after running the code.

This is the script for contact form I am using.

contact.php ( PHP script, ASCII text )

<?php
$field_name = $_POST['message-name'];
$field_email = $_POST['message-email'];
$field_message = $_POST['message'];

$mail_to = 'klixters1@klixters.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'contact.html';
	</script>
<?php
}
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to gordon@template-help.com');
		window.location = 'contact.html';
	</script>
<?php
}
?>

WHAT ERROR??

I suggest you read this page before you post again.

1 Like

Two problems I see:

First, using the built-in PHP mail() function isn’t all that reliable, many would suggest using something like PHPMailer or other more modern library.

Second, you seem to be using the form-fillers email address as the “from” address for sending the email, which won’t work on a lot of mail servers. It is a bad thing to allow mail servers to send from any address, also known as “Open Relay”. Send it from your own email address.

But yes, tell us what error message you get, and on what line.

If the problem is that you just see your javascript alert error message window, that just means for some reason mail() has been unable to send the email to the mail server, but that’s all you can get from it. Another reason, I believe, that something like PHPMailer is considered better.

1 Like