Jump to content

Recommended Posts

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)

 

Error.png

 

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!

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? :\

$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?

$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 :\

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']

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 :D

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.