Contact Us php script check


macrumors 68000
Original poster
Jul 14, 2008
Charlotte, NC
Code is attached below. I have several text boxes on the Contact Us page on the site (on a local environment not on a server yet) but every time I click the Submit button it just shows me the code on the next page. Any ideas what I might be doing wrong or is it because it's not on a server yet (<-- never had this issue before on a local).

Form Script

if(!$_POST) exit;

$email = $_POST['email'];

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
	$error.="Invalid email address entered";
if($errors==1) echo $error;
	$values = array ('name','email','message');
	$required = array('name','email','message');
	$your_email = "";
	$email_subject = "New Message: ".$_POST['subject'];
	$email_content = "new message:\n";
	foreach($values as $key => $value){
		if ($key != 'subject' && $key != 'company') {
		  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
		$email_content .= $value.': '.$_POST[$value]."\n";
	if(@mail($your_email,$email_subject,$email_content)) {
		echo 'Message sent!'; 
	} else {
		echo 'ERROR!';

HTML code on Site:
<form action="contact.php" method="post" id="contactform" name="redirect" value="thankyou.html" />
              <table width="97%">
                  <td width="145" align="left" valign="top" class="body" id="Company"><strong>Company:</strong></td>
                  <td width="280" align="left" valign="top"><input name="Company" type="text" size="30" /></td>
                  <td align="left" valign="top" class="body" id="Contact"><strong>Full Name:</strong></td>
                  <td align="left" valign="top"><input name="Name" type="text" size="30" /></td>
                  <td align="left" valign="top" class="body" id="Address"><strong>Address: </strong></td>
                  <td align="left" valign="top"><input name="Address" type="text" size="30" /></td>
                  <td align="left" valign="top" class="body" id="Phone"><strong> Phone: </strong></td>
                  <td align="left" valign="top"><input name="Phone" type="text" size="30" /></td>
                  <td align="left" valign="top" class="body" id="Email"><strong> Email: </strong></td>
                  <td align="left" valign="top"><input name="Email" type="text" size="30" /></td>
                  <td align="left" valign="top" class="body" id="Comments"><strong> Questions / Comments: </strong></td>
                  <td align="left" valign="top"><textarea name="comments" cols="25" rows="6"></textarea></td>
                  <td><input type="submit" name="submit" class="button" value="Submit" /></td>


macrumors 68030
Oct 31, 2007
Austin, TX
If you're only seeing php code on submit, there's something wrong with your local server's configuration and it's not parsing the script. It's just outputting it as text.

As a side note, eregi has been deprecated as of PHP 5.3.0. Relying on this feature is highly discouraged.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.