Error when submitting form to be emailed

I am helping a friend out with a website which recently developed a problem sending a form. In the past it would email the contents of the form. Currently, it stops and gives an error (“There was an error while attempting to send your request. Please resubmit or try again later”) that is coded. As far as I know, nothing was changed on their server, but the ftp password was changed around the same time they noticed this no longer working. The form itself seems to error check ok. Thanks for any help. Jay

The code follows…

<?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 = "[email protected]"; // $sendto = "[email protected]"; $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 = "

The following errors were found. Please verify your entry and resubmit.

    \n"; foreach ( $errors as $e ) { $message .= "
  • $e
  • \n"; } $message .= "
\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 ) ); ?>

Code reposted
[php]

<?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 = "[email protected]"; // $sendto = "[email protected]"; $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 = "

The following errors were found. Please verify your entry and resubmit.

    \n"; foreach ( $errors as $e ) { $message .= "
  • $e
  • \n"; } $message .= "
\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 ) ); ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service