We have a simple form that validates and sends on to the appropriate person. The form works fine on our testing server, but not on the live sever. I am stumped.

On the live server I get the message "There was an error sending your email. Please try again later." This leads me to believe it is in the below portion of code.

if ($valid) {
	// process the form
	require_once('../includes/email.php');

	if ($process_success) {
		foreach($form_fields as $key=>$value) {
			// clear it out
			${$value} = '';
		}
		$new_location = 'http://statefarmstage.ddbchicago.net/redportfolio/thanks_for_asking/';

		header("Location: " . $new_location);
		exit;
	} else {
		$attention_msg = 'There was an error sending your email. Please try again later.';
		$detail_msg[] = '';
	}
} else {
	if (count($detail_msg) > 1) {
		$single_plural = 's';
	} else {
		$single_plural = '';
	}
	$attention_msg = 'Please correct the following error' . $single_plural . ':';
	$detail_msg[] = '';
}

} else {
foreach($form_fields as $key=>$value) {
// clear it out
${$value} = '';
$v{$value} = TRUE;
}
$valid = TRUE;
$process_success = FALSE;
$attention_msg = '';
$detail_msg = array('');
}

    I'm assuming that $process_success is set in email.php. We'd have to see the code in that file to determine why it's not working.

      <?php
      // enable error reporting
      // error_reporting(E_ALL);

      // vars from the form
      $from_name =${$form_fields[0]};
      $from_email = ${$form_fields[1]};
      $from_zip = ${$form_fields[2]};
      $has_agent = ${$form_fields[3]};
      $this_agent = ${$form_fields[4]};
      $this_subject = ${$form_fields[5]};
      $this_question = ${$form_fields[6]};

      switch ($_SERVER['HTTP_HOST']) {
      case 'statefarmstage.ddbchicago.net':
      $to = 'Andrea Fratto <email@example.com>';
      //$to = 'D. Scott Boyce <email@example.com>';
      break;
      default:
      $to = 'Andrea Fratto <email@example.com>';
      //$to = 'State Farm <email@exampe.com>';
      break;
      }

      $subject = 'A Question from SFRedPortfolio.com (' . $this_subject . ')';

      // the message
      $message = 'Name: ' . $from_name . "\r\n";
      $message .= 'Email: ' . $from_email . "\r\n";
      if ($from_zip != '') {
      $message .= 'ZIP: ' . $from_zip . "\r\n";
      }
      if ($has_agent == 'Yes') {
      $message .= 'Agent: ' . $this_agent . "\r\n";
      }
      $message .= "\r\n";
      $message .= $this_question . "\r\n";
      $message .= "\r\n";

      $headers = '';
      $headers .= 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";

      $headers .= 'From: ' . trim(stripslashes($from_name)) . ' <' . trim(stripslashes($from_email)) . '>, ' . "\r\n";
      $headers .= 'Bcc: ' . trim(stripslashes($from_email)) . "\r\n";
      $headers .= 'Reply-To: ' . trim(stripslashes($from_email)) . "\r\n";
      $headers .= 'X-Mailer: PHP/' . phpversion();

      // in case any of our lines are larger than 70 characters, we should use wordwrap()
      $message = wordwrap($message, 70);

      // send
      if (mail($to, $subject, $message, $headers)) {
      $process_success = TRUE;
      } else {
      $process_success = FALSE;
      }
      ?>

      MOD EDIT: Removed actual e-mail addresses.

        I think the problem is with this snippet:

        if (mail($to, $subject, $message, $headers)) {
        $process_success = TRUE;
        } else {
        $process_success = TRUE;
        }

        For some reason on the live server this info is not getting set properly.

        Could this be their server not having installed and working email system?

        Noah

          I ran a simple mail() function on the live server and confirmed it will send email, so I am stumped. My thought is that the email.php script that I am running somehow has an error that is ignored on the TESTING serving, but fails to mail on the LIVE server. Oh, how joyous my day will be if I solve this problem. Thanks for all the help.

            Write a Reply...