Message part of contact form not working

I am sure I have something wrong here, but dang if I can find it. The contact form works fine except the message does not come through. Perhaps someone could put another set of eyes on it and clue me in? Thanks.
This is the HTML:

<form id="ContactForm" method="post" action="contact.php">
                        		<div>
									<div  class="wrapper">
										<strong>Name:</strong>
										<div class="bg"><input type="text" class="input" name="Name:" ></div>
									</div>
									<div  class="wrapper">
										<strong>Email:</strong>
										<div class="bg"><input type="text" class="input" name="Email:" >	</div>							
									</div>
									<div  class="textarea_box">
										<strong>Message:</strong>
										<div class="bg"><textarea name="textarea" cols="1" rows="1" ></textarea>		</div>						
									</div>
									<a href="#" class="button" onClick="document.getElementById('ContactForm').submit()"><span><span>Send</span></span></a>
									<a href="#" class="button" onClick="document.getElementById('ContactForm').reset()"><span><span>Clear</span></span></a>
								</div>
							</form>

And this is the PHP behind it:

<?php
$field_name = $_POST['Name:'];
$field_email = $_POST['Email:'];
$field_message = $_POST['textarea'];

$mail_to = 'xxxxxxx@xxx.xxx';
$subject = 'Message from a site visitor '.$field_name;

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

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

$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_page.html';
	</script>
<?php
}
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to [email]firstvirginiaservices@yahoo.com[/email]');
		window.location = 'contact_page.html';
	</script>
<?php
}
?>

ok, you define


$field_message = $_POST['textarea'];

but then call

$body_message .= 'Message: '.$field_textarea;

in the actual body_message variable…

Okay, I totally appreciate the response. However I am not as smart as you think I am. I changed the fields that were in red in your response to match one another, but it still doesn’t work. Can you hold my hand just a bit more please?

spikeZ was trying to point out $field_message and $field_textarea are two different variables (not the red text; which is just the color of strings).

In short, you either need to change $field_message to $field_textarea or you need to change $field_textarea to be $field_message

Ah Hah! Thank you so much!!! Cookies for you :slight_smile:

Some ready-made code here:

<?
if(isset($HTTP_POST_VARS[‘act’]) && $HTTP_POST_VARS[‘act’]==“process”) {
//
if($HTTP_POST_VARS[‘name’]!=“” && $HTTP_POST_VARS[‘email’]!=“” && $HTTP_POST_VARS[‘comments’]!=“”) {
//
$headers = “Return-path: <”.stripslashes($HTTP_POST_VARS[‘email’]).">
“;
$headers .= “Reply-to: <”.stripslashes($HTTP_POST_VARS[‘email’]).”>
";
$headers .= "Content-Type: text/html; charset=windows-1252
“;
$headers .= “Content-Transfer-Encoding: 7bit
“;
$headers .= “From: “.stripslashes($HTTP_POST_VARS[‘name’]).”<”.stripslashes($HTTP_POST_VARS[‘email’]).”>”.”
";
$headers .= "X-Priority: 3
";
$headers .= "X-Mailer: EasyCM X-Mailer Version 2.01
";
$headers .= "MIME-Version: 1.0
";
$headers .= "

";
$message = wordwrap(‘<p>Visitor contacted!</p><p>Name: ‘.stripslashes($HTTP_POST_VARS[‘name’]).’<br>Email: ‘.stripslashes($HTTP_POST_VARS[‘email’]).’</p><p>Questions & Comments: ‘.stripslashes($HTTP_POST_VARS[‘comments’]).’</p>’, 70);

$mailto = ‘your@emailaddress.com’;

mail($mailto, ‘From Site Visitor’, $message, $headers);

echo ‘<script>alert(“Your message has been sent!”);</script>’;

unset($HTTP_POST_VARS);
} else {
echo ‘<script>alert(“You have not entered all required information.”);</script>’;
}

}
?>

<table width=“100%” border=“0” cellspacing=“0” cellpadding=“0”>
<tr>
<td><?
//echo ‘<b>’.TEXT_CONTACT_FORM.‘</b>’;
?>
<FORM name=“form1” action=“” method=“post”>
<TABLE class=main style=“WIDTH: 100%; BORDER-COLLAPSE: collapse” cellSpacing=2 cellPadding=2>
<TBODY>
<TR>
<TD>
<INPUT name=name class=“formfield” style=" width: 382px; color: #000000; background: #F1F7F8;" value=“<?=$HTTP_POST_VARS[‘name’];?>” ></TD>
<TD width=“100%” style=“WIDTH: 100%”> - Full Name</TD>
</TR>
<TR>
<TD><INPUT name=email class=“formfield” style=" width: 382px; color: #000;background: #F1F7F8;" value=“<?=$HTTP_POST_VARS[‘email’];?>” ></TD>
<TD style=“WIDTH: 100%”> - Email</TD>
</TR>
<TR>
<TD>
<TEXTAREA name=“comments” class=“formfield” style=" width: 380px; height: 110px;color: #000;background: #F1F7F8;"><?=$HTTP_POST_VARS[‘comments’];?></TEXTAREA></TD>
<TD style=“WIDTH: 100%”> - Comments</TD>
</TR>

<TR>
<TD>
<input type=submit class=“formfield” style=“background: #F1F7F8; width: 140px; HEIGHT: 25px; color: #000000; font-family: Verdana, Sylfaen, Arial” value=“Send Now!” name=submit>
</TD>
<TD style=“WIDTH: 100%”>
<input name=“act” type=“hidden” id=“act” value=“process”>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM></td>
</tr>
</table>

There are many many issues with that code, first and foremost HTTP_POST_VARS was deprecated in version 5.3
http://php.net/manual/en/migration53.deprecated.php

Your code lacks any type of validation, opening up a few different error scenarios.

Lastly, the poster had a workable and usable product, he didn’t need a new way of performing the task, just needed help finding an error in his code.