Jump to content

Error when submitting form to be emailed


jbird327

Recommended Posts

This code is from a pre-existing site, I'm trying to help out but I am out of my element....

The page takes information on a form and then emails the results, but has recently stopped emailing and posts the last error shown in the code.

"There was an error while attempting to send your request. Please resubmit or try again later"

Any obvious problems with the following code?

If the code seems ok, any ideas on what would cause the error?  Thanks for any help.

<?php

require_once( "HTML/IT.php" );
require_once( "HTML/Page.php" );

function fakelastmod()
{
return gmstrftime( "%a, %d %b %G %T %Z" );
}

$templates_dir = "templates";
$sendto = "info@abc.com";
// $sendto = "cfern@abc.com";
$subject = "Tank Quote Request from ";
$mailtmpl = "tankemail.tpl";
$formtmpl = "newtankenq.tpl";
$errors = array();
$blurb = "templates/tankenqblurb.tpl";

$fields = array(
      'reqd' => true, 'reqm' => true, 'reqy' => true,
      'contact' => true,
      'title' => false,
      'company' => true,
      'address' => true, 'addresb' => false,
      'city' => true, 'state' => false, 'zip' => true,
      'country' => false,
      'phone' => true, 'fax' => false,
      'email' => true,
      'usage' => false,
      'model' => false,
  'part' => false,
      'size' => true,
      'lining' => false,
      'layout' => true,
      'support' => false,
      'botheight' => false,
      'numsupp' => false,
      'diam' => true,
      'shell' => false,
      'tan' => false,
      'oalen' => false,
      'press' => true,
      'temp' => true,
      'corros' => false,
      'coropt' => false,
      'material' => true,
      'matopt' => false,
      'mwyloc' => true,
      'noznuma' => false,
      'nozqtya' => false,
      'noznumb' => false,
      'nozqtyb' => false,
      'noznumc' => false,
      'nozqtyc' => false,
      'special' => false
);
$names = array(
      'reqd' => "Day", 'reqm' => "Month", 'reqy' => "Year",
      'contact' => "Contact Name",
      'title' => "Title",
      'company' => "Company Name",
      'address' => "Address Line 1",
      'city' => "City", 'zip' => "Zip/Postal Code",
      'phone' => "Phone Number",
      'fax' => 'Fax Number',
      'email' => "E-mail Address",
      'size' => "Volume",
      'layout' => "Layout",
      'botheight' => "Height from floor to bottom",
      'numsupp' => "No. of supports",
      'diam' => "Diameter",
      'shell' => "Shell Length",
      'tan' => "Tangent-to-Tangent",
      'oalen' => "O.A. Length",
      'press' => "Pressure",
      'temp' => "Temperature",
      'corros' => "Corrosion Allowance",
      'material' => "Material"
      );
      $radios = array( 'layout', 'corros', 'material', 'mwyloc' );
      $rvalues = array(
      'layout' => array( 0 => 'Horizontal', 1 => 'Vertical' ),
      'support' => array( 0 => 'Saddles', 1 => 'Legs' ),
      'corros' => array( 0 => 'None', 1 => '1/16', 2 => '1/8', 3 => 'o' ),
      'material' => array( 0 => 'Carbon steel', 1 => 'SS Type', 2 => 'o' ),
      'mwyloc' => array( 0 => 'Top Head', 1 => 'Shell', 2 => 'Bottom Head', 3 => 'Hinged', 4 => 'Davit' )
      );
      $values = array();

      function filltemplate( $template, $message, $values ) {
      	global $templates_dir, $fields, $radios;

      	$tpl = new IntegratedTemplate( $templates_dir );
      	$tpl->loadTemplateFile( $template, true, true );
      	$tpl->setCurrentBlock( "MESSAGEBLOCK" );
      	$tpl->setVariable( "MESSAGE", $message );
      	$tpl->parseCurrentBlock();
      	$tpl->setCurrentBlock( "FORMBLOCK" );
      	$tpl->setVariable( "SCRIPTNAME", $_SERVER['PHP_SELF'] );
      	foreach ( array_keys( $fields ) as $k ) {
      		if ( isset( $values[$k] ) ) $tpl->setVariable( strtoupper( $k ), $values[$k] );
      	}
      	foreach ( $radios as $r ) {
      		if ( isset( $values[$r] ) ) $tpl->setVariable( strtoupper( substr( $r, 0, 3 ).'CHECK'.chr( 97 + $values[$r] ) ), 'checked="checked"' );
      	}
      	$tpl->parseCurrentBlock();
      	return $tpl->get();
      }

      function mailform( $mailtmpl, $sendto, $values ) {
      	global $templates_dir, $fields, $radios, $rvalues, $subject;

      	$tpl = new IntegratedTemplate( $templates_dir );
      	$tpl->loadTemplateFile( $mailtmpl, true, true );
      	$tpl->setCurrentBlock( "FORMBLOCK" );
      	$tpl->setVariable( "DATE", date( "r" ) );
      	$tpl->setVariable( "REQDATE", date( "j F Y", mktime( 0, 0, 0, $values['reqm'], $values['reqd'], $values['reqy'] ) ) );
      	$tpl->setVariable( "CONTACT", $values['contact'] );
      	$tpl->setVariable( "TITLE", $values['title'] );
      	$tpl->setVariable( "COMPANY", $values['company'] );
      	$tpl->setVariable( "ADDRESS", $values['address'] );
      	$tpl->setVariable( "ADDRESB", $values['addresb'] );
      	$tpl->setVariable( "CITY", $values['city'] );
      	$tpl->setVariable( "STATE", $values['state'] );
      	$tpl->setVariable( "ZIP", $values['zip'] );
      	$tpl->setVariable( "COUNTRY", $values['country'] );
      	$tpl->setVariable( "PHONE", $values['phone'] );
      	$tpl->setVariable( "FAX", $values['fax'] );
      	$tpl->setVariable( "EMAIL", $values['email'] );
      	$tpl->setVariable( "USAGE", $values['usage'] );
      	$tpl->setVariable( "MODEL", $values['model'] );
      	$tpl->setVariable( "Pimages", $values['part'] );
      	$tpl->setVariable( "SIZE", $values['size'] );
      	$tpl->setVariable( "LINING", $values['lining'] );
      	$tpl->setVariable( "LAYOUT", $rvalues['layout'][(int)$values['layout']]  );
      	$tpl->setVariable( "SUPPORT", $rvalues['support'][(int)$values['support']]  );
      	$tpl->setVariable( "BOTHEIGHT", $values['botheight'] );
      	$tpl->setVariable( "NUMSUPP", $values['numsupp'] );
      	$tpl->setVariable( "DIAM", $values['diam'] );
      	$tpl->setVariable( "SHELL", $values['shell'] );
      	$tpl->setVariable( "TAN", $values['tan'] );
      	$tpl->setVariable( "OALEN", $values['oalen'] );
      	$tpl->setVariable( "PRESS", $values['press'] );
      	$tpl->setVariable( "TEMP", $values['temp'] );
      	$tpl->setVariable( "CORROS", $values['corros'] == "3" ? $values['coropt'] : $rvalues['corros'][(int)$values['corros']] );
      	$tpl->setVariable( "MATERIAL", $values['material'] == "2" ? $values['matopt'] : $rvalues['material'][(int)$values['material']] );
      	$tpl->setVariable( "MWYLOC", $rvalues['mwyloc'][(int)$values['mwyloc']]  );
      	$tpl->setVariable( "NOZNUMA", $values['noznuma'] );
      	$tpl->setVariable( "NOZQTYA", $values['nozqtya'] );
      	$tpl->setVariable( "NOZNUMB", $values['noznumb'] );
      	$tpl->setVariable( "NOZQTYB", $values['nozqtyb'] );
      	$tpl->setVariable( "NOZNUMC", $values['noznumc'] );
      	$tpl->setVariable( "NOZQTYC", $values['nozqtyc'] );
      	$tpl->setVariable( "SPECIAL", chunk_split( $values['special'] ) );
      	$tpl->parseCurrentBlock();
      	return mail( $sendto, $subject . $values['company'], $tpl->get(),
         "From: \"" . $values['contact'] . "\" <" . $values['email'] . ">\r\n"
         . "X-Mailer: PHP/" . phpversion() );
      }

      if ( isset( $_POST['submit'] ) ) {
      	foreach ( array_keys( $fields ) as $k ) {
      		if ( isset( $_POST[$k] ) ) {
         $values[$k] = $_POST[$k];
         if ( $fields[$k] && $values[$k] == "" ) {
         	$errors[] = "Missing value in field " . $names[$k] . ".";
         }
         switch ( $k ) {
         	case 'reqy':
         		if ( ! checkdate( $values['reqm'], $values['reqd'], $values['reqy'] ) ) {
         			$errors[] = "Invalid date specified in Required Quote Date.";
         		}
         		break;
         	case 'phone':
         	case 'fax':
         		if ( $values[$k] != "" && ! ereg( "[0-9()\-\+]+", $values[$k] ) ) {
         			$errors[] = "Invalid number in field " . $names[$k] . ".";
         		}
         		break;
         	case 'email':
         		if ( $values[$k] != "" && ! ereg( "[^@]+@[^@]+\.[^@]{2,}", $values[$k] ) ) {
         			$errors[] = "Invalid e-mail address.";
         		}
         		break;
         	case 'size':
         	case 'botheight':
         	case 'numsupp':
         	case 'diam':
         	case 'shell':
         	case 'tan':
         	case 'oalen':
         	case 'press':
         	case 'temp':
         	case 'noznuma':
         	case 'nozqtya':
         	case 'noznumb':
         	case 'nozqtyb':
         	case 'noznumc':
         	case 'nozqtyc':
         		if ( $values[$k] && ! ereg( "[0-9\.\-]+", $values[$k] ) ) {
         			$errors[] = "Invalid value in field " . $names[$k] . ".";
         		}
         		break;
         }
      		}
      	}

      	if ( $values['corros'] == "3" && $values['coropt'] == "" ) {
      		$errors[] = "'Other' selected but nothing specified for Corrosion Allowance.";
      	}
      	if ( $values['material'] == "2" && $values['matopt'] == "" ) {
      		$errors[] = "'Other' selected but nothing specified for Material.";
      	}

      	if ( count( $errors ) ) {
      		$message = "<p>The following errors were found. Please verify your entry and resubmit.</p><ul>\n";
      		foreach ( $errors as $e ) {
         $message .= "<li>$e</li>\n";
      		}
      		$message .= "</ul>\n";
      	} else {
      		if ( mailform( $mailtmpl, $sendto, $values ) ) {
         $message = "Your request has been sent successfully. Thank you for your interest.";
      		}
      		else {
         $message = "There was an error while attempting to send your request. Please resubmit or try again later.";
      		}
      	}
      } else {
      	$message = implode( "\n", file( $blurb ) );
      }

      header( "Last-Modified: " . fakelastmod() );
      print( filltemplate( $formtmpl, $message, $values ) );

      ?>

Link to comment
Share on other sites

The code calls a function mailform, that returns the value of the mail function. Since this is returning false, it means that the mail is not being accepted.  Is this an existing site that has stopped working or an attempt to use this script on a new site?  What has changed?

Link to comment
Share on other sites

This is an existing site that was working. The form itself seems to work ok, as it will catch the errors and give the proper response. If the mail part of the code seems ok, where would be the next place to look? From some quick reading, I see there might/should be a php.ini file somewhere - is this where the mail function gets it's information? The company self hosts the site, and has an IT guy on staff. The only information I have so far is that they have been replacing some servers. If the mail function goes through their email server, is there somewhere in the code (or ini) that would point to that server?  Thanks.

Link to comment
Share on other sites

This is an existing site that was working. The form itself seems to work ok, as it will catch the errors and give the proper response. If the mail part of the code seems ok, where would be the next place to look? From some quick reading, I see there might/should be a php.ini file somewhere - is this where the mail function gets it's information? The company self hosts the site, and has an IT guy on staff. The only information I have so far is that they have been replacing some servers. If the mail function goes through their email server, is there somewhere in the code (or ini) that would point to that server?  Thanks.

 

Yes there are configuration items that would effect what method mail uses.  See http://us3.php.net/manual/en/mail.configuration.php

 

If this is a windows server, and they have changed something to do with the mail server this could be where it is broken. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.