Web Hosting Talk







View Full Version : mail.php problem


cem
06-04-2004, 06:11 PM
I've uploaded PHP Mail Form (www.xentrik.net) on my site - for some reason whenever i fill in the form and click on submit it redirects back to the form while it should redirect to a page saying thank you for your feedback or something,... I'm not the only one who get redirected back - everyone has the same problem on my server - i've uploaded this php script on another server and it works just great. So i guess its a server side problem - but i have no idea what - the script worked a couple months ago and now all of a sudden it doesn't - anyone have any ideas on what could be causing this ? Here is the the script:


<!-- Copyright © 2002 Kali (http://kali.xentrik.net) -->

<html>
<head>
<title>Kali's PHP Contact Form</title>

<?php
// COPYRIGHT/LIABILITY NOTICE
// Copyright © 2002 Kali (http://kali.xentrik.net)

// Kali's Contact Form may be used and modified free of charge as long as this
// copyright notice and the comments above remain intact. By using this code
// you agree to indemnify Kali from any liability that might arise from its use.

// Selling the code for this program without prior written consent is not permitted.
// Permission must be obtained before redistributing this software. In all cases the
// copyright and header information must remain intact.

// MODIFY THE FOLLOWING SECTION

// your name
$recipientname = "YOUR NAME";

// your email
$recipientemail = "YOU@YOURDOMAIN.COM";

// subject of the email sent to you
$subject = "Online-Form Response for $recipientname";

// send an autoresponse to the user?
$autoresponse = "yes";

// subject of autoresponse
$autosubject = "Thank you for your mail!";

// autoresponse message
$automessage = "This is an auto response to let you know that we've successfully
received your email sent through our email form.
Thanks! We'll get back to you shortly.";

// 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>";

// END OF NECESSARY MODIFICATIONS

?>

<style type="text/css"><!--
td,body,input,textarea {
font-size:12px;
font-family:Verdana,Arial,Helvetica,sans-serif;
color:#000000}
--></style>
</head>
<body>

<table width="100%" height="100%"><tr>
<td valign="top"><font face="Verdana,Arial,Helvetica" size="2">

<?php
if($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
$hurrah = mail($toemail,"$subject","$message","From: $Name <$Email>");
if($hurrah) {
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="toemail" value="<?php echo $recipientemail; ?>">
<input type="hidden" name="toname" value="<?php echo $recipientname; ?>">
<input type="hidden" name="require" value="Name,Email,Comments">
<table><tr>
<td colspan="2" align="center"><b>Contact Me!</b><p></td>
</tr><tr>
<td valign="top" align="right">Name:</td>
<td valign="top"><input name="Name" size="25"></td>
</tr><tr>
<td valign="top" align="right">E-mail:</td>
<td valign="top"><input name="Email" size="25"></td>
</tr><tr>
<td valign="top" align="right">Comments:</td>
<td valign="top"><textarea name="Comments" rows="5" cols="35"></textarea></td>
</tr><tr>
<td colspan="2" align="center"><input type="submit" value="Submit" name="submitform">
<input type="reset" value="Reset" name="reset"></td>
</tr></table>
<br>

</form>
<?php } ?>
</font><p></td>
</tr><tr>
<td valign="bottom"><font face="Verdana" size="1">
Mailform Copyright © 2002 <a href="http://www.xentrik.net/">
Kali's Web Shoppe</a>.</font></td>
</tr></table>

</body>
</html>


Any help is appriciated!

zupanm
06-04-2004, 06:16 PM
this is a poorly coded php app. If you register_globals on then it won't run.. which is what you are setting.

like this
if($submitform) {

should be
if($_POST['submitform']) {


and a bunch more changes

cem
06-04-2004, 06:30 PM
oh man you helped me a LOT! register_globals was off i've changed it too on and now it works just great! thanks

NEO-Charlie
06-04-2004, 06:36 PM
Originally posted by cem
oh man you helped me a LOT! register_globals was off i've changed it too on and now it works just great! thanks

I'd recommend modifying the script to work with register_globals OFF rather than turning that on for one single PHP script.

Setting register_globals on can* cause problems and make some scripts exploitable.

*Can does not mean that it will, just that it is more likely than with it off.

daejuanj
06-04-2004, 06:45 PM
Originally posted by zupanm
this is a poorly coded php app. If you register_globals on then it won't run.. which is what you are setting.

like this
if($submitform) {

should be
if($_POST['submitform']) {


and a bunch more changes
Yeah, I have to agree, this is a poorly nuke-style coding in this script. Editing it to work with Registered Globals OFF takes about 2min.

You can use $_POST or $_REQUEST.

BTW, this thread could be in the Programming forum:D

cem
06-04-2004, 06:59 PM
Unfortunately i dont know how to script in PHP - anyone have the spare time to give me a hand? ;)

linux-tech
06-04-2004, 07:03 PM
Originally posted by cem
Unfortunately i dont know how to script in PHP - anyone have the spare time to give me a hand? ;)
http://www.php.net = all the hand you'll need. Take a look through their functions and go from there :)

cem
06-04-2004, 07:11 PM
Changed if($submitform) { to if($_POST['submitform']) {

now it keeps telling me "Invalid email address"

register_globals is turned off

daejuanj
06-04-2004, 07:18 PM
Originally posted by cem
Changedf($submitform) { to if($_POST['submitform']) {

now it keeps telling me "Invalid email address"

register_globals is turned off
You have to changed the other variables too.

cem
06-04-2004, 07:52 PM
Originally posted by daejuanj
You have to changed the other variables too.

go on :D

daejuanj
06-04-2004, 07:59 PM
Originally posted by cem
go on :D
I don't have time to create/edit one for you, today, but PM me, if you don't find another way. That code could be a lot better. And I'm just too lazy.;)

jason_s
06-04-2004, 08:24 PM
Please don't use this script. Anyone can use it to send spam if they can find it. (there are dorks scanning for this kind of script all the time) - Atleast you didn't post your url here ..

It's not php, but try this:
http://nms-cgi.sourceforge.net/scripts.shtml

daejuanj
06-04-2004, 08:26 PM
You can also look at http://phpformgen.sourceforge.net/

cem
06-05-2004, 10:03 AM
i'll give those a try - thanks guys