I've written a katrillion forms before.

I cannot for the life of me figure out why this one isn't sending a confirmation e-mail.

Can someone please! Please help me before I lose my mind?

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$mailto = "email@scrink.com" ;
$subject = "CANR Communication Request Form" ;
$errorurl = "http://ag.udel.edu/test/christy/commForm/error.html" ;
$thankyouurl = "http://ag.udel.edu/test/christy/commForm/thankyou.html" ;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$department = $_POST['department'] ;
$phone = $_POST['phone'] ;
$accountcode = $_POST['accountcode'] ;
$projectname = $_POST['projectname'] ;
$completiondate = $_POST['completiondate'] ;
$approver = $_POST['approver'];
$writing_request = $_POST['writing_request'] ;
$writing_other = $_POST['writing_other'] ;
$graphic_design = $_POST['graphic_design'] ;
$photography = $_POST['photography'] ;
$photography_other = $_POST['photography_other'] ;
$format = $_POST['format'] ;
$website = $_POST['website'] ;
$website_other = $_POST['website_other'] ;
$more_description = $_POST['more_description'] ;

$http_referrer = "http://ag.udel.edu/test/christy/commForm/form.html" ;

//$target_path = "uploads/";

// Where the file is going to be placed 
$target_path = 'D:/websites/anrwebsite/test/christy/commForm/'.$_FILES['uploadfile']['name'];

//******                        PROCESSING BEGINS HERE
if($_SERVER['REQUEST_METHOD'] == "GET") {
  print "<br><strong>TERMINATED</strong><br>";
  exit;
}

$uploadfile = $_POST['uploadfile'];
// start for loop
for($x=0;$x<$uploadfile;$x++){
$file_name = $_FILES['uploadfile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadfile'. $x]['tmp_name'], $target_path);
 // check if successfully copied
 if($copy){
 echo "$file_name | uploaded sucessfully!<br>";
 }else{
 echo "$file_name | could not be uploaded!<br>";
 }
} // end of loop
	
if(eregi("\r", $subject)) die("<B>Error Exit</B> Possible Spam Bot attack. Carriage return not allowed in subject");
if(eregi("\n", $subject)) die("<B>Error Exit</B> Possible Spam Bot attack. Line feed not allowed in subject");
if(eregi("\r", $email)) die("<B>Error Exit</B> Possible Spam Bot attack. Carriage return not allowed in header");
if(eregi("\n", $email)) die("<B>Error Exit</B> Possible Spam Bot attack. Line feed not allowed in header");
if(eregi("\r", $name)) die("<B>Error Exit</B> Possible Spam Bot attack. Carriage return not allowed in header");
if(eregi("\n", $name)) die("<B>Error Exit</B> Possible Spam Bot attack. Line feed not allowed in header");

// Validate email field.

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0 || substr_count($exploded_email[1],".") > 3){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $key => $value){if($key == 0){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}elseif(strlen($value) > 6 || !preg_match('/^[a-z0-9]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

$messageproper =

	"This message was sent from:\n" .
	"$http_referrer\n" .
	"------------------------------------------------------------\n" .
	"Name of sender: $name\n" .
	"Email of sender: $email\n" .
    "Department: $department\n" .
	"Phone: $phone\n" .
	"Account code: $accountcode\n" .
	"Project name: $projectname\n" .
	"CompletionDate: $completiondate\n" .
	"Final approver of project: $approver\n" .
	"What type of writing request, if any: $writing_request\n" .
	"Is there a different writing request you need: $writing_other\n" .
	"What type of graphic design request, if any: $graphic_design\n" .
	"What type of photography, if any: $photography\n" .
	"Is there a different photography request you need: $photograhy_other\n" .
	"What photo format would you like: $format\n" .
	"What type of website work do you need: $website" .
	"Is there a different website request you need: $website_other\n" .
	"If necessary, please provide a more details description: $more_description\n" .
	
	"\n\n------------------------------------------------------------\n" ;
	"Filename: ".$_FILES['uploadfile']['name'];

mail($mailto, $subject, $messageproper,	"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>
Member Avatar for iamthwee

Why am I not surprised?

First of all why don't you indent your code properly so you can actually read it.

Yours

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0 || substr_count($exploded_email[1],".") > 3){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $key => $value){if($key == 0){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}elseif(strlen($value) > 6 || !preg_match('/^[a-z0-9]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

mine

if ( isset ( $_REQUEST['email'] ) && !empty ( $_REQUEST['email'] ) )
{
  if ( preg_match ( "/(%0A|%0D|\n+|\r+|:)/i", $_REQUEST['email'] ) )
  {
    $errors[] = "Email address may not contain a new line or a colon";
  }
  $_REQUEST['email'] = trim ( $_REQUEST['email'] );
  if ( substr_count ( $_REQUEST['email'], "@" ) != 1 || stristr ( $_REQUEST['email'], " " ) )
  {
    $errors[] = "Email address is invalid";
  }
  else
  {
    $exploded_email = explode ( "@", $_REQUEST['email'] );
    if ( empty ( $exploded_email[0] ) || strlen ( $exploded_email[0] ) > 64 || empty ( $exploded_email[1] ) )
    {
      $errors[] = "Email address is invalid";
    }
    else
    {
      if ( substr_count ( $exploded_email[1], "." ) == 0 || substr_count ( $exploded_email[1], "." ) > 3 )
      {
        $errors[] = "Email address is invalid";
      }
      else
      {
        $exploded_domain = explode ( ".", $exploded_email[1] );
        if ( in_array ( "", $exploded_domain ) )
        {
          $errors[] = "Email address is invalid";
        }
        else
        {
          foreach ( $exploded_domain as $key = > $value )
          {
            if ( $key == 0 )
            {
              if ( strlen ( $value ) > 63 || !preg_match ( '/^[a-z0-9-]+$/i', $value ) )
              {
                $errors[] = "Email address is invalid";
                break;
              }
            }
            elseif ( strlen ( $value ) > 6 || !preg_match ( '/^[a-z0-9]+$/i', $value ) )
            {
              $errors[] = "Email address is invalid";
              break;
            }
          }
        }
      }
    }
  }

The next step would be to go through each section individually and test if it works. If it doesn't, then break the section into smaller more managable pieces to test...etc.

Um. Thanks, I guess.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.