PHP Contact form Problems

Hey im a newbee to PHP, so dont laugh…

basically i have created this Contact from…

[php]<form action="contact.php"method=“post”>

      <label for="Name">Name:</label>

      <input type="text" name="name" id="name" required placeholder="Name" />

      <label for="name">Contact:</label>

      <input type="text" name="Contact" id="subject" required placeholder="Contact Number" />

      <label for="email">Email:</label>

      <input type="email" name="email" id="email" required placeholder="[email protected]" />

      <label for="message">Message:</label>

      <textarea name="message" id="message" required placeholder= "please be as detailed as possible"/></textarea>

      <input type="submit" value=Send Message"<address> />

    </form>[/php]

It was part of a template i downloaded, and i have been working on it a while, the PHP associated with this is as follows…

[php]<?php
$field_name = $_POST[‘cf_name’];
$field_Contact = $_POST[‘cf_Contact’];
$field_Email = $_POST[‘cf_Email’];
$field_Message = $_POST[‘cf_Message’];

$mail_to = ‘[email protected]’;
$subject = 'Survey Request From BBS Website '.$field_name;

$body_message .= '$From: '.$name."\n";
$body_message .= '$Contact: '.$Contact."\n";
$body_message .= '$E-mail: '.$email."\n";
$body_message .= '$Message: '.$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) { ?>

<?php } else { ?>
<script language="javascript" type="text/javascript">
	alert('Im sorry something has gone wrong!');
	window.location = 'HTTp://www.bbsurveys.co.uk';
</script>
<?php } ?>[/php]

here is my problem, it all works fine, when i press send, it says thank you very much, but the Email i receive is just…

$email
$contact
$message

i can see why it is doing it, i just cant see a way of fixing it to include the text in the field.

Lack of PHP knowledge i think
Any help would be greatly appreciated

cheers Rio

You are assigning the post var to certain vars but then using different vars in the body to send, so they don’t match.
$field_name doesn’t match $name

Hi Fastsol, cheers for replying…

[php]<?php
$field_name = $_POST[‘cf_name’];
$field_Contact = $_POST[‘cf_Contact’];
$field_Email = $_POST[‘cf_Email’];
$field_Message = $_POST[‘cf_Message’];

$mail_to = ‘[email protected]’;
$subject = 'Survey Request From BBS Website '.$field_name;

$body_message .= '$From: '.$field_name."\n";
$body_message .= '$Contact: '.$field_Contact."\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";[/php]

Could you perhaps edit one line, so i can see what i am doing wrong…

cheers rio

p.s…

when i receive the email it says (no sender)

Again, the var on these lines
[php]$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";[/php]
Doesn’t match $field_Email

They now all match as you suggested.

But the email i receive from the website just says
$mail
$message
$subject

And so on, how do i get the message or subject i type in to appear in the email.

Cheers rio

You got one more problem, you names from the input are not the same as those from the POST[…];
Try this

[php]
$field_name = $_POST[‘name’];
$field_Contact = $_POST[‘Contact’];
$field_Email = $_POST[‘email’];
$field_Message = $_POST[‘message’];

	$mail_to = '[email protected]';
	$subject = 'Survey Request From BBS Website  '.$field_name;

	$body_message .= '$From: '.$field_name."\n";
	$body_message .= '$Contact: '.$field_Contact."\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. We will contact you shortly.');
			window.location = 'HTTp://www.bbsurveys.co.uk';
		</script>
	<?php
	}
	else { ?>
		<script language="javascript" type="text/javascript">
			alert('Im sorry something has gone wrong!');
			window.location = 'HTTp://www.bbsurveys.co.uk';
		</script>
	<?php
	}

?>
[/php]

i think you should use isset() at each POST and !empty();

[php]

<?php if(isset($_POST['name']) && isset($_POST['Contact']) && isset($_POST['email']) && isset($_POST['message']) && !empty($_POST['name']) && !empty($_POST['Contact']) && !empty($_POST['email']) && !empty($_POST['message'])){ $field_name = $_POST['name']; $field_Contact = $_POST['Contact']; $field_Email = $_POST['email']; $field_Message = $_POST['message']; $mail_to = '[email protected]'; $subject = 'Survey Request From BBS Website '.$field_name; $body_message .= '$From: '.$field_name."\n"; $body_message .= '$Contact: '.$field_Contact."\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. We will contact you shortly.');
			window.location = 'HTTp://www.bbsurveys.co.uk';
		</script>
	<?php
	}
	else { ?>
		<script language="javascript" type="text/javascript">
			alert('Im sorry something has gone wrong!');
			window.location = 'HTTp://www.bbsurveys.co.uk';
		</script>
	<?php
	}

}
?>

[/php]

Let us know if this works.

Cheers

i think you should use isset() at each POST and !empty();
You would only need to use the !empty(). That will evaluate to the same degree as isset() with half the code.
Sponsor our Newsletter | Privacy Policy | Terms of Service