Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP email form not working, error page displayed regardless of content submitted
    primarykey
    data
    text
    <p>I have a company team page that uses a switch statement in the PHP send file to determine the email address of the person, and then send the person a message based on a pop-up form. The form comes up okay, displays the correct person's name, but whenever I enter form data as a test to submit it, it errors out and says:</p> <blockquote> <p>We are very sorry, but there were error(s) found with the form you submitted. These errors appear below. We are very sorry, but there appears to be a problem with the form you submitted. Please RETURN and fix these errors.</p> </blockquote> <p>I inherited the maintenace of this site and I have no idea how long this feature has been broken, how many e-mails have not been sent, how many times people have been frustrated by this, so I'm trying to get it fixed as fast as possible. I've modified the switch statement here so I don't give away any company info... just pulled out all the people and added 2 generic cases. Hope you get it. This is the file staff_contact_send.php</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Staff Contact&lt;/title&gt; &lt;link href="enginuity.css" rel="stylesheet" type="text/css" /&gt; &lt;style type="text/css"&gt; &lt;!-- .style9 {font-size: 12px; font-weight: bold; color: #FFFFFF; } .style10 { color: #2A1F00; font-weight: bold; font-size: 16px; } --&gt; &lt;/style&gt; &lt;script type="text/javascript" src="Scripts/contact.js"&gt;&lt;/script&gt; &lt;script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;?php switch ($_GET["staffname"]) { case "username1": $email_to = "username1@thiswebsite-llc.com"; break; case "username2": $email_to = "username2@thiswebiste-llc.com"; break; default: echo "An error has occured. Please contact our office at 717-796-9226. Thank You."; } ?&gt; &lt;?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED function died($error) { // your error code can go here echo "&lt;br /&gt;&lt;br /&gt;&lt;p align=\"center\" class=\"eHelp\"&gt;We are very sorry, but there were error(s) found with the form you submitted. &lt;/p&gt;"; echo "&lt;p align=\"center\" class=\"eHelp\"&gt;These errors appear below.&lt;br /&gt;&lt;/p&gt;"; echo "&lt;p align=\"center\" class=\"eHelp\"&gt;" . $error . "&lt;br /&gt;&lt;/p&gt;"; echo "&lt;p align=\"center\" class=\"eHelp\"&gt;Please &lt;a style=\"font-weight:bold; font-size:20px\" href=\"javascript:history.go(-1)\"&gt;RETURN&lt;/a&gt; and fix these errors.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['subject']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $subject = $_POST['subject']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= '-The email address you entered does not appear to be valid.&lt;br /&gt;'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= '-Please enter your first name.&lt;br /&gt;'; } if(!preg_match($string_exp,$message)) { $error_message .= '-Please enter a message.&lt;br /&gt;'; } if(!preg_match($string_exp,$subject)) { $error_message .= '-Please enter a subject line.&lt;br /&gt;'; } if(strlen($error_message) &gt; 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Phone: ".clean_string($phone)."\n"; $email_message .= "Message: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $subject, $message, $headers); ?&gt; &lt;!-- include your own success html here --&gt; &lt;p align="center" class="style7"&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center" class="style7"&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center" class="eHelp"&gt;Thank You.&lt;/p&gt; &lt;p align="center" class="eHelp"&gt;Your message has been sent.&lt;/p&gt; &lt;p align="center"&gt;&amp;nbsp;&lt;/p&gt; &lt;p align="center"&gt;&lt;span class="style10"&gt;&lt;a href="javascript:window.close()" class="redlinks"&gt;Close Window&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;?php } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>=========</p> <p>Here is the code for the form... staff_contact.php</p> <p>=========</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Staff Contact&lt;/title&gt; &lt;style type="text/css"&gt; &lt;!-- .style9 {font-size: 12px; font-weight: bold; color: #FFFFFF; } --&gt; &lt;/style&gt; &lt;link href="enginuity.css" rel="stylesheet" type="text/css" /&gt; &lt;style type="text/css"&gt; &lt;!-- .style10 { color: #2A1F00; font-weight: bold; font-size: 16px; } --&gt; &lt;/style&gt; &lt;script type="text/javascript" src="Scripts/contact.js"&gt;&lt;/script&gt; &lt;script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt;&lt;br /&gt; &lt;?php switch ($_GET["staffname"]) { case "username1": $staff_name = "User Name"; break; case "username2": $staff_name = "User Name"; break; default: echo "&lt;p align=\"center\" style=\"color:#fff\"&gt;An error has occured. Please contact our office at 717-796-9226. Thank You.&lt;/p&gt;"; } ?&gt; &lt;form method="post" action="staff_contact_send.php?staffname=&lt;?php echo $_GET["staffname"]; ?&gt;" id="contact"&gt; &lt;table width="610" border="1" cellpadding="6" cellspacing="0" bordercolor="#000000"&gt; &lt;tr&gt; &lt;td bgcolor="#CA1814"&gt;&amp;nbsp;&lt;/td&gt; &lt;td bgcolor="#FFFFFF" class="redheader"&gt;Contact &lt;?php echo $staff_name; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="84" bgcolor="#CA1814" class="style9"&gt;&lt;div align="right"&gt;&lt;span class="eHelp"&gt;*Name:&lt;/span&gt;&lt;/div&gt;&lt;/td&gt; &lt;td width="496" bgcolor="#FFFFFF"&gt;&lt;input name="Name" type="text" id="Name" size="58" tabindex="1" value="Name" onclick="this.value = '';" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="84" bgcolor="#CA1814" class="style9"&gt;&lt;div align="right" class="eHelp"&gt;*E-mail:&lt;/div&gt;&lt;/td&gt; &lt;td bgcolor="#FFFFFF"&gt;&lt;input name="email" type="text" id="email" tabindex="2" value="Email" size="58" onclick="this.value = '';" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="84" bgcolor="#CA1814" class="style9"&gt;&lt;div align="right" class="eHelp"&gt;Phone:&lt;/div&gt;&lt;/td&gt; &lt;td bgcolor="#FFFFFF"&gt;&lt;input name="phone" type="text" id="phone" size="20" tabindex="3" value="Phone" onclick="this.value = '';" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="84" bgcolor="#CA1814" class="style9"&gt;&lt;div align="right" class="eHelp"&gt;*Subject:&lt;/div&gt;&lt;/td&gt; &lt;td bgcolor="#FFFFFF"&gt;&lt;input name="subject" type="text" id="subject" size="58" tabindex="4" value="Subject" onclick="this.value = '';"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="84" valign="top" bgcolor="#CA1814" class="style9"&gt;&lt;div align="right" class="eHelp"&gt;*Message:&lt;/div&gt;&lt;/td&gt; &lt;td bgcolor="#FFFFFF"&gt;&lt;textarea name="message" cols="58" rows="5" id="message" tabindex="5" onclick="this.value = '';"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr bgcolor="#CA1814"&gt; &lt;td colspan="2" align="center"&gt;&lt;div align="center"&gt; &lt;input type="submit" name="Submit" value="Submit" /&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload