tomstirling1979 Posted February 11, 2009 Share Posted February 11, 2009 I am trying to create a form on my website that sends an email to the specific email address of my choice. I also need to create a "success message" that displays when the user submits there information, but that the message simply appears under the form on the same page, and not on a new page. I had this working before, and then I had to switch the site to goDaddy and then I no longer got the success message. I am a total novice and just need some advice to get this fixed fast. The code is below for people to examine. <?php $email = 'thomas_stirling@hotmail.com'; // email who you're sending to $subject = $_POST['subject']; //email subject $headers = 'From: Clearly Creative Homepage Leads' . "\r\n" . 'Reply-To: thomas_stirling@hotmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message = ''; $errorStr = ''; if(isset($_POST['submit'])) { /* define required fields */ $requiredFields = array( 'Company Name' => 'companyname', 'Name' => 'name', 'EMail' => 'email', 'Message' =>'message' ); /* valudate required fields */ foreach($requiredFields as $key => $value) { if($_POST[$value] == '') { $errorStr .= "Error: Field $key is required <br />"; } } /* if all fields validated, send the email */ if($errorStr == '') { /* Create Message */ $messageFields = array( 'Company Name' => $_POST['companyname'], 'Name' => $_POST['name'], 'E-Mail' => $_POST['email'], 'Message' => $_POST['message'] ); foreach($messageFields as $key => $value) { $message .= "$key : $value \n"; } mail($email, $subject, $message, $headers); $sent = 1; } } ?> <!-- this is the form starting--> <form action="index_sidebar_test.php" method="POST"> <font class="sidebarDate">Company Name *</font><br /> <input width="200" name="companyname" type="text"/><br /> <font class="sidebarDate">Full Name *</font><br /> <input width="200" name="name" type="text" /><br /> <font class="sidebarDate">Email Address *</font><br /> <input width="200" name="email" type="text" /> <br /> <font class="sidebarDate">Message *</font><br /> <textarea cols=20 rows=4 name="message" /></textarea> <br /><br /> <input type="submit" value="Submit" name="submit"/></form> <?php if($sent == 1 && isset($_POST['submit']) ) {\ ?> <span class="Main_HeadingText">Thanks for your submission.<br /> We’ll get back to you within one business day.</span> <? } elseif ($errorStr != '') { print $errorStr; } ?> <!-- this is the form ending --> Quote Link to comment Share on other sites More sharing options...
peranha Posted February 11, 2009 Share Posted February 11, 2009 change the <? to <?php in the following code <? } elseif ($errorStr != '') { print $errorStr; } ?> I dont think that godaddy supports php short tags. I never got them to work. Also use [ code] [ /code] tags (without the space) it color codes things and makes it easier to read. Also what is the \ for here if($sent == 1 && isset($_POST['submit']) ) {\ Quote Link to comment Share on other sites More sharing options...
tomstirling1979 Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks, that worked great!!!! Quote Link to comment Share on other sites More sharing options...
peranha Posted February 11, 2009 Share Posted February 11, 2009 Yeah, never use short tags as this will happen, because some servers dont support it. Always use the full <?php tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.