Contact Us php script check

Discussion in 'Web Design and Development' started by AFPoster, Jan 15, 2012.

  1. AFPoster macrumors 65816

    Joined:
    Jul 14, 2008
    Location:
    Charlotte, NC
    #1
    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>
     
  2. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #2
    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.
     
  3. AFPoster thread starter macrumors 65816

    Joined:
    Jul 14, 2008
    Location:
    Charlotte, NC
    #3
    Any tips for switching off of this then?


    I figured it was a Local host thing, I'm sure it will fix itself when it goes Remote.
     
  4. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #4
    See preg_match.
     
  5. AFPoster thread starter macrumors 65816

    Joined:
    Jul 14, 2008
    Location:
    Charlotte, NC
    #5
  6. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #6
    Ignore them, it's a spam bot.

    jW
     

Share This Page