Email Contact Form never submits

I am new to php and the code is basically jibberish to me (I don’t like variables), but I have a contact form I am creating for a website. I did use some canned php code and created my own html contact form. However, when I click submit on the contact form it does nothing. The php code does not popup, nor does the error or thank you page. I have no idea what the problem is I have tried it on my local MAMP server, my web server (1and1) and even on free hosting site just to see if the problem could be php configuration. Same result every time. Here is both the php and the html code (minus a lot of the stylistic stuff if anyone thanks its necessary then I can post that too) for the contact page because I don’t know where the problem could be. I even plugged it into a php code checker and got no errors.
[php]<?php

$webmaster_email = "[email protected]";

$feedback_page = “contact_form.html”;
$error_page = “error_message.html”;
$thankyou_page = “thank_you.html”;

$Full_Name = $_REQUEST[‘Full_Name’] ;
$City = $_REQUEST[‘City’] ;
$State = $_REQUEST[‘State’] ;
$Email_Address = $_REQUEST[‘Email_Address’] ;
$Comments = $_REQUEST[‘Comments’] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST[‘email_address’])) {
header( “Location: $feedback_page” );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( “Location: $error_page” );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( “$webmaster_email”, “Feedback Form Results”,
$comments, “From: $email_address” );
header( “Location: $thankyou_page” );
}
?>[/php]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<body>

  <div class="content">


   
    <p>&nbsp; </p>
    <h1 align=center class="content">Contact TxOHC</h1>
    <div class="hi">Thank you for your interest</div>
   </p>
    <p class="content">&nbsp;</p>
  <form method="post" action="send_mail.php"  >
   
   
  
   
    <label>Full Name
<input name="Full_Name" type="text" class="required" id="Full_Name"size="50" maxlength="200"  />
    </label>
   
   <p></p>
     <p>
       <label>City
         <input type="text" name="City"   id="City">
       </label>
        <label>State
         <input name="State" type="text"   id="State" size="10">
    </label>
      
         
           <label><br />
             <br />
             Email Address
             <input name="Email_Address" type="text" class="required" id="Email_Address" size="30" maxlength="200">
       </label>

     </p>

     </p>
     <p>&nbsp;  </p>
     <p>Questions and Comments</p>
     <p>
       <textarea name="Comments" cols="50" rows="15
  "></textarea>
     </p>
   
  
  

     <p>&nbsp;</p>
     <p align=center> <input type="submit" value="Submit" /></p>
  
    

     
<p>
 
</p>
   </form>
   
   

  </div>
  
<!-- end .container --></div>
</body>
</html>

you don’t need quotes around a variable in the mail function and you’re missing headers, except for the From part.

Thank you for your help, I think I figured out the variable issue and managed to get a different result. Now when I hit submit send_mail.php comes up as a white screen. My limited understanding of headers makes me think that is the issue at hand, but I am not sure what to do there. All I have read has said headers send you to a new page and I have headers to send you to the Error_Page.html (or back to the contact page) in case of an error and Thankyou_Page.html in case of no error. What other(s) do I need to get this to work? Or is it something completely different that I am missing. Below is the new code so you can see the changes. Thank you for your help.

[php]<?php

 //  $MP = "sendmail_path	/usr/sbin/sendmail -t -i";

$Webmaster_Email = "[email protected]";

$Contact_Page = “contact_form.html”;
$Error_Page = “error_message.html”;
$Thankyou_Page = “thank_you.html”;

$Full_Name = $_REQUEST[‘Full_Name’] ;
$City = $_REQUEST[‘City’] ;
$State = $_REQUEST[‘State’] ;
$Email_Address = $_REQUEST[‘Email_Address’] ;
$Comments = $_REQUEST[‘Comments’] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST[‘Email_Address’])) {
header( “Location: $Contact_Page” );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($Email_Address) ) {
header( “Location: $Error_Page” );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail($Webmaster_Email, “Contact Form Results”, $Full_Name, $City, $State,
$Comments, From: $Email_Address );
header( “Location: $Thankyou_Page” );
}
?>[/php]

Those aren’t the headers im talking about. ill post an example when I get home.

I researched what I think you are talking abut and I adjusted the code, and now it redirects to the Thank You page. However, the email still does not send. I checked the e-mail, the online box my mail program, the junk mail in both places and no message. Again I have no idea what the problem is or why the email is not sending. My guess would be an issue with the To value or Mail function or even the placement of the functions. Having said that I have no idea what the problem is I’ve tried a few things and the only change took me back to the previous issue. Thank you for all of your help in figuring this out.

[php]<?php

  $MP = "sendmail_path /usr/sbin/sendmail -t -i";

$Webmaster_Email = "[email protected]";

$Contact_Page = “contact_form.html”;
$Error_Page = “error_message.html”;
$Thankyou_Page = “thank_you.html”;

$Full_Name = $_REQUEST[‘Full_Name’] ;
$City = $_REQUEST[‘City’] ;
$State = $_REQUEST[‘State’] ;
$Email_Address = $_REQUEST[‘Email_Address’] ;
$Comments = $_REQUEST[‘Comments’] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST[‘Email_Address’])) {
header( “Location: $Contact_Page” );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($Email_Address) ) {
header( “Location: $Error_Page” );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {

$headers = ‘MIME-Version: 1.0’ . “\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\n”;

$headers .= “From: ‘.$Email_Address.’”;
$headers .=“To: ‘.$Webmaster_Email.’”;

// Send
mail($Webmaster_Email, “Contact Form Results”, $Full_Name, $City, $State, $Email_Address,
$Comments );
header( “Location: $Thankyou_Page” );
}

?>[/php]

I have messed with the code again and no changes in actually sending the email. I don’t know if there is an error I’m not seeing, something I’m missing, if I just made the whole thing too convoluted, or if something is in the wrong order. I’m likely missing something to make it send, but beyond the sendmail path (up at the top of the code) I don’t know what else would tell the code to send the email. All of your help is appreciated.

[php]<?php

  $MP = "sendmail_path /usr/sbin/sendmail -t -i";

$Webmaster_Email = "[email protected]";

$Contact_Page = “contact_form.html”;
$Error_Page = “error_message.html”;
$Thankyou_Page = “thank_you.html”;

$Full_Name = $_REQUEST[‘Full_Name’] ;
$City = $_REQUEST[‘City’] ;
$State = $_REQUEST[‘State’] ;
$Email_Address = $_REQUEST[‘Email_Address’] ;
$Comments = $_REQUEST[‘Comments’] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST[‘Email_Address’])) {
header( “Location: $Contact_Page” );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($Email_Address) ) {
header( “Location: $Error_Page” );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {

$headers = ‘MIME-Version: 1.0’ . “\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\n”;

/*$headers .= “From: ‘.$Email_Address.’”;
$headers .=“To: ‘.$Webmaster_Email.’”;

$Message =“Contact Form Results”;

$Message = “$Full_Name\r\n$City\r\n$State\r\n$Email_Address\r\n”;*/

// Send

$MTo = $Webmaster_Email;
$MSubject = “Contact Form Entry”;
$Message = “$Full_name, $City, $State, $Email_Address, $Comments”;

mail($MTo, $MSubject, $Message);
header( “Location: $Thankyou_Page” );
}

?>[/php]

Thank you for all your help I hate to do this but I still cannot figure out this latest issue so if someone could look at the latest version of code and give me a clue that would be greatly appreciated. Thank you.

Sponsor our Newsletter | Privacy Policy | Terms of Service