CyberShot Posted April 18, 2010 Share Posted April 18, 2010 Here is the html for the form. When I push the submit button, it just goes to a white screen. Its not refreshing the screen back to the index which is the last line of code <form method="post" action="action.php"> <h3 id="contactIcon">Contact us</h3> <div id="col1"> <label for="name">Name</label><br /><input type="text" id="name" name="name" /><br /> <label for="email">Email</label><br /><input type="text" id="email" name="subject" /><br /> </div><!--END col1--> <div id="col2"> <label id="comments" for="comments">Comments</label><br /><textarea rows="6" cols="15" name="comments"></textarea> </div><!--END col2--> <div class="clear"></div> <input id="send" type="submit" name="submit" value="" /> </form> and the php <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "my_email.com"; $email_subject = "test email"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <meta http-equiv="Refresh" content="0;URL=index.html" /> <? } ?> Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/ Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 You have nothing to display when its sucessful, like an echo after the mail() function. Also, remove the refresh. It's not needed. In your code use headers. header("LOCATION: mysite.com"); Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044268 Share on other sites More sharing options...
CyberShot Posted April 18, 2010 Author Share Posted April 18, 2010 i have a refresh in there to take you to a new page. but above that, the email isn't sending. I am not getting anything after submitting to my email Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044271 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 I'll try fix something up. Also.. <input id="send" type="submit" name="submit" value="" /> why is the value "" ? Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044274 Share on other sites More sharing options...
CyberShot Posted April 18, 2010 Author Share Posted April 18, 2010 I used an image for the submit button Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044275 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 Try this <?php if(isset($_POST['submit'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "my_email.com"; $email_subject = "test email"; $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required // validation expected data exists if(empty($first_name) || empty($email_from) || empty($comments)) { $error_message[] = 'You must fill in all required fields!'; } else { $error_message = ''; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message[] = 'Your Email Address includes invalid characters!.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message[] = 'Your First Name includes invalid characters! <br />'; } if(strlen($comments) < 2) { $error_message[] = 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.<br /><br />"; foreach($error_message as $error) { echo $error."<br /><br />"; } echo "Please go back and fix these errors.<br /><br />"; die(); } else { $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 .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $mail = @mail($email_to, $email_subject, $email_message, $headers); if($mail) { header("LOCATION: /index.php"); } else { echo 'Something appeared to have gone wrong, contact the administrator'; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044282 Share on other sites More sharing options...
CyberShot Posted April 18, 2010 Author Share Posted April 18, 2010 I had the same issue. I tried changing this line @mail = @mail($email_to, $email_subject, $email_message, $headers); to mail = @mail($email_to, $email_subject, $email_message, $headers); that got a response, but still isn't working Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044285 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 It was suppose to be $mail. I was assigning it to a variable to search for the error. Remove the @ before mail. $mail = mail($email_to, $email_subject, $email_message, $headers); and to confirm, action.php is the file with that php in right? Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044287 Share on other sites More sharing options...
CyberShot Posted April 18, 2010 Author Share Posted April 18, 2010 I did as you asked. Also the file name is confirmed as you can see in the html form that I posted. I still get the same issue. nothing happens. the page goes blank when I push send. Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044291 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 Do you have this online that I can view? Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044296 Share on other sites More sharing options...
CyberShot Posted April 18, 2010 Author Share Posted April 18, 2010 yes, but I am messing with two different scripts right now. this one I have been using but for some reason just stopped working for this site. I do get emails from it but they are blank. Here is the error message I got from it Warning: reset() [function.reset]: Passed variable is not an array or object in /home7/public_html//test/action.php on line 14 Warning: Variable passed to each() is not an array or object in /home7/public_html/test/action.php on line 16 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <TITLE>thanks</TITLE> </HEAD> <BODY style="background-color : transparent;" > <?PHP $email = $HTTP_POST_VARS[email]; $mailto = "my-email.net"; $mailsubj = "information from contact page"; $mailhead = "From: $email\n"; reset ($HTTP_POST_VARS); $mailbody = "Values submitted from contact page:\n"; while (list ($key, $val) = each ($HTTP_POST_VARS)) { if ($key!="submit") { $mailbody .= "$key : $val\n"; } } mail($mailto, $mailsubj, $mailbody, $mailhead); ?> <META HTTP-EQUIV="REFRESH" CONTENT="100;URL=index.html"> </dIV> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/198944-help-with-my-contact-form-script/#findComment-1044301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.