# Thread: windows2003 and PHP problem...

1. Registered User
Join Date
Apr 2005
Posts
46

## Unanswered: windows2003 and PHP problem...

I am trying to do a simple mail script that sends an attachment.
This is working 100% when i test it on my unix server running
PHP 4.3.x.

I am trying to use this script on a windows2003 server running
PHP 4.4.4, but it is acting all wierd. The admin ran the standard
php installer (didn't understand the instructions for the manual
install).

The mail function itself works fine, but i am getting several
errors:

Notice: Undefined index: [name of field] in D:\path\to\mail.php on line 27
Notice: Undefined offset: 1 in D:\path\to\mail.php on line 70

Thoughts, suggestions?
i wish they were using unix, but aren't able to swtich.

2. Registered User
Join Date
Apr 2005
Posts
46
Note: I have about 30 fields on the email form. I am only getting an error for a few of them (some radiobuttons, some text fields).... some of hte WORKING fields are both, text and radiobuttons. i've checked the syntax and its fine. (hence, it working flawlessly in unix). i am assuming that i have to have the admin adjust some setting on the windows side (beyond permissions...)

3. Registered User
Join Date
Apr 2006
Location
Denver, Co. USA
Posts
242
The two notice messages indicate logic or syntax errors that PHP makes an assumption about and continues execution. Whatever is causing them exists on both systems but because of the error_reporting level or the display_errors setting, you don't see them on the Unix system. These are written to the web server's error log and cause a small speed penalty when they are logged.

To get specific help with eliminating the problems in the code that are causing these notice messages, you need to post your code.

4. Registered User
Join Date
Apr 2005
Posts
46
I have edited out all of the other form information (there are a lot of fields).
Also, oddly enough, after refreshing it a few times, the errors magically dissapeared, EXCEPT for this one:

Notice: Undefined index: lalala in D:\sites\company\test\mail.php on line 63

Here is the code for the form:

Code:
<form action="mail.php" method="post" enctype="multipart/form-data" name="email" id="email">

<input name="lalala" type="file" id="lalala" />

(Must be a PDF (.pdf) or Word document (.doc)

<input type="submit" name="Submit" value="Submit" />

</form>
Here is the code for mail.php:
Code:
<?php
$file_name =$_FILES['lalala']['name'];
$ext = explode(".",$file_name);

if (!($ext[1] == "pdf" ||$ext[1] == "doc"))
die("Resume must be a PDF or word Document");

$target_path =$FirstName . "_resume" . "." . $ext[1]; if(!(move_uploaded_file($_FILES['lalala']['tmp_name'], $target_path))) die('There was an error uploading the file');$fileatt = $target_path;$fileatt_type = "application/octet-stream";
$fileatt_name =$FirstName . "_resume" . $ext[1];$email_to = "xxxxxxxxx";

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers = "From: " .$email_from;
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

$email_message .= "message....\n\n";$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" .$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" . " name=\"{$target_path}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$target_path}\"\n" . "Content-Transfer-Encoding: base64\n\n" .$data . "\n\n" .
"--{$mime_boundary}--\n";$ok = @mail($email_to,$email_subject, $email_message,$headers);

if($ok) { unlink($target_path);
}
else
{
die("Sorry but the email could not be sent.");
}

?>
The system admin hasn't adjusted the permissions yet so "unlink" isn't working...but when i disable that, everything works perfect, except for the error mentioned above.

thoughts?

5. Registered User
Join Date
Apr 2005
Posts
46
Any thoughts guys?

6. Registered User
Join Date
Apr 2006
Location
Denver, Co. USA
Posts
242
There is nothing in the posted code at the line number indicated in the error message that would cause the error listed. Is the code posted the actual code that caused the actual error message referencing line #63?

7. Registered User
Join Date
Apr 2005
Posts
46
yes, this is the actual code. Again, it works perfectly on UNIX, but gives errors on Windows 2003. could it be some internal setting conflict?

8. Registered User
Join Date
Apr 2006
Location
Denver, Co. USA
Posts
242
Ignoring the line number mismatch, I was able to reproduce your error message two ways -
1) The form field name does not match (for example lalalla) in which case $_FILES['lalala']['name'] does not exist. 2) File uploads are disabled in the php.ini file_uploads = Off in which case$_FILES['lalala']['name'] does not exist.

I can also think of two additional ways that $_FILES['lalala'] would not exist - 1) The temp folder that the uploaded file is put into does not exist or is not writable by the web server/PHP. 2) The size of the uploaded file exceeds the value of the POST_MAX_SIZE directive in php.ini. This results in a NULL$_FILES variable.

9. Registered User
Join Date
Apr 2005
Posts
46
I am going to be having the web admin check the permissions and reconfigure the php.ini file on Wed to the above specs. The script, as is, does upload the file and email it, so I am boggled as to why it would give the error, etc. i did notice, however, that in creating the file on the server, one must write the path otherwise it creates it in the www root directory.

10. Registered User
Join Date
Apr 2005
Posts
46
Ok, I have found the source of the errors.

If the form is left blank, and I make any reference to the field, then an error (like this) is spit out:

Notice: Undefined index: Field in D:\sites\company\mail_test\mail.php on line 4

I know that I could just disactivate errors on hte windows machine, but it seems wrong to do as a work around. Below is my code, can you think of a better work around? (PS: i did try $_REQUEST, to no avail): Code: if (!$_POST['Email'] | !$_POST['LastName'] | !$_POST['FirstName']) {
die("fail.");
}

11. Registered User
Join Date
Apr 2006
Location
Denver, Co. USA
Posts
242
PHP Code:
 <?php error_reporting(E_ALL); // your installation apparently has this setting in php.ini // existing code - evaluates variable that might not exist if(!$_POST['any']){ echo "no post<br />"; } // proper way to test for the existence of a variable if(!isset($_POST['any'])){ echo "no post<br />"; } // alternate way to existing code which suppresses any error message if(!@$_POST['any']){ echo "no post<br />"; } // suppress notice messages in script or in php.ini error_reporting(E_ALL ^ E_NOTICE); // note that this is the default error setting in php.ini // if you are getting notice messages with a default installation, you might want to consider what else is not setup correctly if(!$_POST['any']){ echo "no post<br />"; } ?> 

12. Registered User
Join Date
Apr 2005
Posts
46
Result:

Code:
Notice: Undefined index: field in D:\sites\company\mail_test\mail.php on line 7

no post
no post
no post
no post
it shows them ALL.

13. Registered User
Join Date
Apr 2006
Location
Denver, Co. USA
Posts
242
Is that a question or a statement?

Of course all four if statements are executed, in the same way that your original code sent your emails. There was no fatal error to prevent execution, only a notice message.

Only the first form causes a notice message to be output to the browser.

The second form properly tests for the existence of a variable without generating any error.

The third form suppress the output of the message to the browser.

The fourth form sets the error reporting so as to not output notice messages to the browser.

14. Registered User
Join Date
Apr 2005
Posts
46
Right, but the error:

Code:
Notice: Undefined index: field in D:\sites\company\mail_test\mail.php on line 7
Still appears at the top of the page (above the "no post"s)...

15. Registered User
Join Date
Apr 2005
Posts
46
Forgive my ignorance, I see what you had meant. I have changed my code to:

Code:
if (!isset($_POST['Email']) | !isset($_POST['LastName']) | !isset(\$_POST['FirstName'])) {
die("missing field.");
}
and it works. Thank you so much!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•