spoontard Posted October 4, 2009 Share Posted October 4, 2009 I am rather new too PHP and i found a email form for a website on another site and edited slightly to suit my needs better, however it will not send to the specified email, it redirects on the same page with an error. I just can't seem to figure out what is causing it Any help would be greatly appreciated! <html> <head> <title>BLANK</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <?php // your name $recipientname = "BLANK"; // your email $recipientemail = "BLANK"; // subject of the email sent to you $subject = "Contact form for $recipientname"; // send an autoresponse to the user? $autoresponse = "yes"; // subject of autoresponse $autosubject = "Thank you for your message."; // autoresponse message $automessage = "We have received your message and will get back to you as soon as possible."; // thankyou displayed after the user clicks "submit" $thanks = "Thank you for contacting us.<br>We will get back to you as soon as possible.<br>"; ?> </head> <body> <div id="mainwrap"> <?php include("header.php"); ?> <?php include("leftnav.php"); ?> <div id="contentwrap"> <div id="breadcrumb"></div> <div id="content"> <h2>Still Under Development...</h2> <?php if($_POST['submitform']) { $Name = $HTTP_POST_VARS['Name']; $Email = $HTTP_POST_VARS['Email']; $Comments = $HTTP_POST_VARS['Comments']; // check required fields $dcheck = explode(",",$require); while(list($check) = each($dcheck)) { if(!$$dcheck[$check]) { $error .= "Missing $dcheck[$check]<br>"; } } // check email address if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){ $error .= "Invalid email address<br>";} // display errors if($error) { ?> <b>Error</b><br> <?php echo $error; ?><br> <a href="#" onClick="history.go(-1)">try again</a> <?php } else { $browser = $HTTP_USER_AGENT; $ip = $REMOTE_ADDR; // format message $message = "Online-Form Response for $recipientname: Name: $Name Email: $Email Comments: $Comments ----------------------------- Browser: $browser User IP: $ip"; // send mail and print success message mail($recipientemail,"$subject","$message","From: $Name <$Email>"); if($autoresponse == "yes") { $autosubject = stripslashes($autosubject); $automessage = stripslashes($automessage); mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>"); } echo "$thanks"; } } else { ?> <form name="contactform" action="<?php echo $PHP_SELF; ?>" method="post"> <input type="hidden" name="require" value="Name,Email,Comments"> <br> Name <br> <input name="Name" size="25"> <br> <br> E-mail<br> <input name="Email" size="25"> <br> <br> Comments<br> <textarea name="Comments" rows="5" cols="35"></textarea> <br> <br> <input type="submit" value="Submit" name="submitform"> <input type="reset" value="Reset" name="reset"> </p> <br> </form> <?php } ?> </div> </div> <?php include("footer.php"); ?> </div> </body> </html> This is the contactus.php page which is the main page with the form layout etc.(Email etc blanked out for my privacy) This is what it links to on the same page, i just can't seem to fix it no matter what i do ! Please help Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/ Share on other sites More sharing options...
cags Posted October 4, 2009 Share Posted October 4, 2009 What version of PHP are you using? I believe $HTTP_POST_VARS is a deprecated variable as of ver. 5. Try changing any instances of that to $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930225 Share on other sites More sharing options...
spoontard Posted October 4, 2009 Author Share Posted October 4, 2009 What version of PHP are you using? I believe $HTTP_POST_VARS is a deprecated variable as of ver. 5. Try changing any instances of that to $_POST. It was on php4, so i switched it to php5. I then changed the code that you told me too and no luck so i changed it back to php4 and still no luck. Any more ideas? :\ Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930264 Share on other sites More sharing options...
mikesta707 Posted October 4, 2009 Share Posted October 4, 2009 $HTTP_POST_VARS still work in php4 and 5 but they are deprecated. if you notice you use the variable $recipientemail here mail($recipientemail,"$subject","$message","From: $Name <$Email>"); but that var is set as the string "BLANK" here $recipientemail = "BLANK"; that probably has something to do with your email script not working. Is there an error? What does the error message say? Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930270 Share on other sites More sharing options...
spoontard Posted October 4, 2009 Author Share Posted October 4, 2009 $HTTP_POST_VARS still work in php4 and 5 but they are deprecated. if you notice you use the variable $recipientemail here mail($recipientemail,"$subject","$message","From: $Name <$Email>"); but that var is set as the string "BLANK" here $recipientemail = "BLANK"; that probably has something to do with your email script not working. Is there an error? What does the error message say? If you read under my code i gave a reason why it says blank So where it says "Blank" an email is in its place.. I just can't see why it would not be working :\ Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930278 Share on other sites More sharing options...
cags Posted October 4, 2009 Share Posted October 4, 2009 These three variables are also deprecated I believe... $browser = $HTTP_USER_AGENT; // should be $_SERVER['HTTP_USER_AGENT']; $ip = $REMOTE_ADDR; // should be $_SERVER['REMOTE']; <?php echo $PHP_SELF; ?> // should be $_SERVER['PHP_SELF']; On this line... if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){ ereg should probably be replaced by preg_match as the function is either deprecated, or very soon to be, not entirely sure which. But the reason it isn't working is this line here.... $dcheck = explode(",",$require); Replace $require with $_POST['require'] Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930279 Share on other sites More sharing options...
spoontard Posted October 4, 2009 Author Share Posted October 4, 2009 These three variables are also deprecated I believe... $browser = $HTTP_USER_AGENT; // should be $_SERVER['HTTP_USER_AGENT']; $ip = $REMOTE_ADDR; // should be $_SERVER['REMOTE']; <?php echo $PHP_SELF; ?> // should be $_SERVER['PHP_SELF']; On this line... if ((!ereg(".+\@.+\..+", $Email)) || (!ereg("^[a-zA-Z0-9_@.-]+$", $Email))){ ereg should probably be replaced by preg_match as the function is either deprecated, or very soon to be, not entirely sure which. But the reason it isn't working is this line here.... $dcheck = explode(",",$require); Replace $require with $_POST['require'] Thank you so much! However i changed the ereg to preg_match, caused errors so i changed it back and the same with :- <?php echo $PHP_SELF; ?> // should be $_SERVER['PHP_SELF']; So i left it to echo. But all is well and good so thanks for the help mate Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930281 Share on other sites More sharing options...
cags Posted October 4, 2009 Share Posted October 4, 2009 Perhaps I should have been more specific... <?php echo $PHP_SELF; ?> // should be <?php echo $_SERVER['PHP_SELF']; ?> As for the preg_match, it's because regex patterns used with preg_match must have delimeters. But nevermind. EDIT: Btw if problems solved, theres a SOLVED button in the bottom left of your screen to click. Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930282 Share on other sites More sharing options...
spoontard Posted October 4, 2009 Author Share Posted October 4, 2009 Perhaps I should have been more specific... <?php echo $PHP_SELF; ?> // should be <?php echo $_SERVER['PHP_SELF']; ?> As for the preg_match, it's because regex patterns used with preg_match must have delimeters. But nevermind. EDIT: Btw if problems solved, theres a SOLVED button in the bottom left of your screen to click. thanks lol Quote Link to comment https://forums.phpfreaks.com/topic/176462-solved-email-form-not-working-as-it-should/#findComment-930300 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.