Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AFPoster

macrumors 68000
Original poster
Jul 14, 2008
1,565
152
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
Code:
<?php

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";
	$errors=1;
}
if($errors==1) echo $error;
else{
	$values = array ('name','email','message');
	$required = array('name','email','message');
	 
	$your_email = "info@mysite.com";
	$email_subject = "New Message: ".$_POST['subject'];
	$email_content = "new message:\n";
	
	foreach($values as $key => $value){
	  if(in_array($value,$required)){
		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:
Code:
<form action="contact.php" method="post" id="contactform" name="redirect" value="thankyou.html" />
              <table width="97%">
                <tr>
                  <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>
                </tr>
                <tr>
                  <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>
                </tr>
                <tr>
                  <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>
                </tr>
                <tr>
                  <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>
                </tr>
                <tr>
                  <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>
                </tr>
                <tr>
                  <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>
                </tr>
                <tr>
                  <td></td>
                  <td><input type="submit" name="submit" class="button" value="Submit" /></td>
                </tr>
              </table>
            </form>
 
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.