PHP Form Emailer problems


#1

Hey. I have been recently messing around with premade Form Emailer script that I have been sprucing up and editing a bit so it works with my site’s order form. It has a few checkboxes that turned up with errors but by adding simple if statements I corrected that problem. However, I am still receiving errors in the script:

Notice: Use of undefined constant HTTP_CLIENT_IP - assumed 'HTTP_CLIENT_IP' in C:Websitesvdospecialtiesform_emailer.php on line 59

Notice: Use of undefined constant REMOTE_ADDR - assumed ‘REMOTE_ADDR’ in C:Websitesvdospecialtiesform_emailer.php on line 63

Notice: Undefined index: in C:Websitesvdospecialtiesform_emailer.php on line 91

Notice: Undefined index: in C:Websitesvdospecialtiesform_emailer.php on line 92

Notice: Undefined variable: comments in C:Websitesvdospecialtiesform_emailer.php on line 135

I do not know what causes these problems…the first two errors do not even make sense because I deleted that portion of the script that was made to retreive IP’s because I had no use for it, but for some reason it still returns an error. The other I do not quite know how to fix and I would like any help anyone can offer on this situation.

Here is my form emailer code:

<?php
##################################################
## Email sender by: Steve "Defender" Cunningham ##
##################################################
##												##
## Edit the proper variables to make the script ##
## work on your site.                           ##
##												##
##################################################
##												##
## If I'm not busy, you can email me at:        ##
## sc_99_99@yahoo.com and I can try to help     ##
## you with your problem.						##
##												##
##################################################
##												##
## Note that if the copyright info is deleted,  ##
## this script is no longer valid.              ##
##												##
##################################################

//Define some variables

$youremail="mixmazter@msn.com"; // This is the address that the information submitted will be sent to.

$emailsubject="Repair/Mod Order"; // This will the email's subject

// The From field will be be where this email came from.
// Note on the from field. the text after the first " mark, until the < is what appears in "From" in your email program.
// So, you can put anything alpha numeric here. That would be any letters A-Z and a-z, as well as 0-9
$from_who="Repair/Mod Order Form";

$pagetitle="Thank you!"; // Title to be displayed on the sent info page.

// Enter the code that you want to appear before the information submitted.
// Make sure you put a / mark before all double quotation marks or the script won't work.
// the n at the end of the line is to create a new line in the HTML SOURCE. It DOES NOT create a break or new line
// when viewing it on the internet. Put these at the end of each line in the header and footer if you wish.
// They aren't required.

$header = "<!-- Begin Header -->n
<table>n
 <tr>n
  <td bgcolor="000000"><font color="FFFFFF" size="2" face="verdana">n
<!-- End Header -->n";

// Enter the code you'd like displayed after the information submitted.
// Make sure you put a / mark before all double quotation marks or the script won't work.
// the n at the end of the line is to create a new line in the HTML SOURCE. It DOES NOT create a break or new line
// when viewing it on the internet. Put these at the end of each line in the header and footer if you wish.
// They aren't required.

$footer = "<!-- Begin Footer -->n
</td></tr></table>n
<!-- End Footer -->n";

// This code gets the ip address of the person submiting the form.
// You shouldn't remove it if you want to use this feature.

// If your server uses php version 4.2 or above, you can leave this section alone.

// Otherwise, add 2 slashes (//) to the beginning of the following 4 lines and delete the // in the section below.

$Name = $_POST['Name'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Model = $_POST['Model'];
$Serial = $_POST['Serial'];
if($_POST['Repair1']) $Repair1 = $_POST['Repair1'];
if($_POST['Repair0']) $Repair1 = $_POST['Repair0'];
if($_POST['Mod1']) $Repair1 = $_POST['Mod1'];
if($_POST['Mod0']) $Repair1 = $_POST['Mod0'];
if($_POST['Express1']) $Repair1 = $_POST['Express1'];
if($_POST['Express0']) $Repair1 = $_POST['Express0'];
$Repair_Cost = $_POST['Repair_Cost'];
$Mod_Cost = $_POST['Mod_Cost'];
$Shipping_Handling = $_POST['Shipping_Handling'];
$Total_Cost = $_POST['Total_Cost'];
$Payment_Method = $_POST['Payment_Method'];
$Routing_Code = $_POST['Routing_Code'];
$Bank_Account_Number = $_POST['Bank_Account_Number'];
$Check_Number = $_POST['Check_Number'];
$Problem = $_POST['Problem'];

//$firstname = $HTTP_POST_VARS['firstname'];
//$email = $HTTP_POST_VARS['email'];
//$url = $HTTP_POST_VARS['url'];
//$comments = $HTTP_POST_VARS['url'];


// Edit the following lines to customize how the email sent to you will look.
// To add more fields, just copy and paste the line, and edit the info between the " marks.
// The last 2 lines will send the users browser information and their ip number with the mail.
// Just in case. :)

$mailbody="Name:n=================n$Namenn"; 
$mailbody="Address:n=================n$Addressnn";
$mailbody="City:n=================n$Citynn";
$mailbody="State:n=================n$Statenn";
$mailbody="Zip:n=================n$Zipnn";
$mailbody="Email:n=================n$Emailnn";
$mailbody="Phone:n=================n$Phonenn";
$mailbody="Model:n=================n$Modelnn";
$mailbody="Serial:n=================n$Serialnn";
$mailbody="Repair Yes:n=================n$Repair1nn";
$mailbody="Repair No:n=================n$Repair0nn";
$mailbody="Mod Yes:n=================n$Mod1nn";
$mailbody="Mod No:n=================n$Mod0nn";
$mailbody="Express Yes:n=================n$Express1nn";
$mailbody="Express No:n=================n$Express0nn";
$mailbody="Repair Cost:n=================n$Repair_Costnn";
$mailbody="Mod Cost:n=================n$Mod_Costnn";
$mailbody="Shipping and Handling:n=================n$Shipping_Handlingnn";
$mailbody="Total Cost:n=================n$Total_Costnn";
$mailbody="Payment Method:n=================n$Payment_Methodnn";
$mailbody="Routing Code:n=================n$Routing_Codenn";
$mailbody="Bank Account Number:n=================n$Bank_Account_Numbernn";
$mailbody="Check Number:n=================n$Check_Numbernn";
$mailbody="Problem:n=================n$Problemnn";

mail("$youremail", "$emailsubject", "$mailbody", "From: $from_who");  // Send the email.

$comments = nl2br($comments);

// Page HTML comes next.
?>
<html>
<head>
<title><?php $pagetitle ?></title>
</head>
<body>
<?php print $header;
// A note about the following.
// Each of the printed values here correspond to a field in the form.
// Change this area if you change what fields are in the form.
?>
Submitted information:<br><br>
Name: $Name
<p>
Address: $Address
<p>
City, State, Zip: $City , $State $Zip
<p>
E-Mail: $Email
<p>
Phone: $Phone
<p>
---------------------------------------
<p>
Model: $Model
<p>
Serial #: $Serial
<p>
Repair Yes: $Repair1 Repair No: $Repair0
<p>
Mod Yes: $Mod1 Mod No:$Mod0
<p>
Express Yes: $Express1 Express No: $Express0
<p>
Repair Cost: $Repair_Cost
<p>
Mod Cost: $Mod_Cost
<p>
S&H: $Shipping_Handling
<p>
Total Cost: $Total_Cost
<p>
Payment Method: $Payment_Method
<p>
Routing Code: $Routing_Code
<p>
Bank Account Number: $Bank_Account_Number
<p>
Check Number: $Check_Number
<p>
Problem: $Problem
<?php print $footer; ?>

<!-- DO NOT EDIT BELOW THIS LINE. -->
<!-- DO NOT EDIT BELOW THIS LINE. -->

<?php
// This is a free script, PLEASE leave my copyright notice.
$date=date("Y");
if ($date==2001){
  echo "<br>n<font size="1" face="verdana">nThis script is Copyright &copy;";
  echo (date("Y"));
  echo "&nbsp;Steven "<a href="mailto:defender@3dartisan.net">Defender</a>" Cunninghamn";
}
else
{
print "<br>n<font size="1" face="verdana">nThis script is Copyright &copy; 2001-";
print (date("Y"));
print "&nbsp;Steven "<a href="mailto:defender@3dartisan.net">Defender</a>" Cunninghamn";
}
?>
<!-- DO NOT EDIT THE ABOVE LINES -->
<!-- DO NOT EDIT THE ABOVE LINES -->
</body>
</html>

#2

well first we kind of need to know WHERE the problem is. You gave us the error messages which have the line numbers but I personally am not willing to wade through the code to find variables or count the lines by hand.

So here is my $0.02:
I think the first 2 notices are looking for the part you deleted. Whether or not you had need of that part, the script may because it is trying to find it.

The others I would need to know exactly which lines are throwing the problems.

Good luck!


#3

yea sorry about that. but ill define the error lines right here

here are the new errors

Notice: Use of undefined constant HTTP_CLIENT_IP - assumed 'HTTP_CLIENT_IP' in C:Websitesvdospecialtiesform_emailer.php on line 59

Notice: Use of undefined constant REMOTE_ADDR - assumed ‘REMOTE_ADDR’ in C:Websitesvdospecialtiesform_emailer.php on line 63

Notice: Undefined index: Repair0 in C:Websitesvdospecialtiesform_emailer.php on line 80

Notice: Undefined index: Mod0 in C:Websitesvdospecialtiesform_emailer.php on line 82

Notice: Undefined index: Express0 in C:Websitesvdospecialtiesform_emailer.php on line 84

Notice: Undefined variable: Repair0 in C:Websitesvdospecialtiesform_emailer.php on line 118

Notice: Undefined variable: Mod0 in C:Websitesvdospecialtiesform_emailer.php on line 120

Notice: Undefined variable: Express0 in C:Websitesvdospecialtiesform_emailer.php on line 122

Notice: Undefined variable: comments in C:Websitesvdospecialtiesform_emailer.php on line 135

and the lines with the errors are:

(59-63)

if (getenv(HTTP_CLIENT_IP)){ 
$user_ip=getenv(HTTP_CLIENT_IP); 
} 
else { 
$user_ip=getenv(REMOTE_ADDR); 
}

(79-84)

if($_POST['Repair1']) $Repair1 = $_POST['Repair1'];
if($_POST['Repair0']) $Repair0 = $_POST['Repair0'];
if($_POST['Mod1']) $Mod1 = $_POST['Mod1'];
if($_POST['Mod0']) $Mod0 = $_POST['Mod0'];
if($_POST['Express1']) $Express1 = $_POST['Express1'];
if($_POST['Express0']) $Express0 = $_POST['Express0'];

(117-122)

$mailbody="Repair Yes:n=================n$Repair1nn";
$mailbody="Repair No:n=================n$Repair0nn";
$mailbody="Mod Yes:n=================n$Mod1nn";
$mailbody="Mod No:n=================n$Mod0nn";
$mailbody="Express Yes:n=================n$Express1nn";
$mailbody="Express No:n=================n$Express0nn";

(135)

$comments = nl2br($comments);

#4

getenv(HTTP_CLIENT_IP) should be getenv(“HTTP_CLIENT_IP”)
Same for remote address

Try adding this

// This will NOT report uninitialized variables
error_reporting (E_ERROR | E_WARNING |
                  E_PARSE);

#5

hmm…the script you gave me didnt seem to remove the errors of undefined variables and indexes if that is what it was supposed to do? however adding the " in HTTP_CLIENT_IP and REMOTE_ADDR worked :D

That aside…

I forgot to add…the only thing the script emails me, is the problem text field…

for example.

Problem

asfasdfasdfasdfasdfasdf

EDIT:

btw:

if($_POST['Express0']) $Express0 = $_POST['Express0'];

i meant this code to be like if Express0 exists (anything other than null), then set it as a global variable. I did this because PHP resembles a form of mIRC script, IRC chatting software if you aren’t familiar with it.
Does this even work for PHP?


#6

hello?


#7

Because of your level of error reporting, the UNDEFINED variables are just, that UNDEFINED.

You are requesting a variable that doesn’t exisit ,$_POST[‘Repair0’], (perhaps it wasn’t passed) so although your IF statement is false (and doesn’t execute the code) the variable doesn’t exist, and reports an error.

I like to use the tertiary funciton of the ? operator.

Instead of
[php]

if($_POST[‘Repair0’]) $Repair0 = $_POST[‘Repair0’];

[/php]

I would use :
[php]
$Repair0 = !empty($_POST[‘Repair0’]) ? $_POST[‘Repair0’] : ‘’ ;
[/php]

The above has the same result without errors and defines the variables in the same process. Long hand it could look like this:

[php]

if (!empty($_POST[‘Repair0’])) {
$Repair0 = $_POST[‘Repair0’] ;
} else {
$Repair0 = ‘’;
}
[/php]

Alternatively, you could shut the error reporting off via the PHP or you could preceed the statement with the @ operator to supress the error on that line of code.

[php]

@if($_POST[‘Repair0’]) $Repair0 = $_POST[‘Repair0’];

[/php]

Although the errors can be suppressed, it should be done with caution as debugging other problems may be difficult as well.

Good luck


#8

Thanks!

I’m going to try it right now. I’ll let you know the outcome.


#9

Wonderful!

It narrowed down the UNDEFINED variable errors to just one:

Notice: Undefined variable: comments in C:Websitesvdospecialtiesform_emailer.php on line 133

I deleted that line, and there is no more errors, since that variable, $comments, was never set to begin with…

One problem still remains however. When I receive the email that the PHP sent to me, it only contains one of the fields the user enters. The $Problem field.

Problem:

fgsdfgsdfgsdfgs

It isn’t submitting the rest of the information to me.

$mailbody="Name:n=================n$Namenn"; 
$mailbody="Address:n=================n$Addressnn";
$mailbody="City:n=================n$Citynn";
$mailbody="State:n=================n$Statenn";
$mailbody="Zip:n=================n$Zipnn";

I think I may be able to answer my own question on this…so correct me if I’m wrong. I’m guessing it keeps setting $mailbody over and over again re-writing the original? If that is the case how do I prevent that and send a message with all the information in it?


#10

Yep…I answered my own question, lol.

Thanks for the help guys!