Cristian Boariu
Cristian Boariu

Reputation: 9621

Php include issue

I am new in php and I am trying to do a contact form.

In my contact.php file I am including Mail.php from pear mail package (I've copied Mail.php and its Mail folder in my root because I don't have ssh access to install this directly).

Now in my php I put this:

<?php
if(!@file_exists('./Mail.php') ) {
    echo 'can not include';
} else {
   include('./Mail.php');
}
//rest of the code
 ?>

For some unknown reason I get this:

    The website encountered an error while retrieving http://example.com/contact.php. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

If I comment include statement the error is no longer occuring... I don't understand WHAT I am doing wrong...I am sure that Mail.php is in the same root dir with my contact.php file.

Upvotes: 0

Views: 144

Answers (3)

Ashley Strout
Ashley Strout

Reputation: 6268

With include, it tries to import the requested file. If it fails, it continues on, only generating a warning. Since you are getting an fatal error with the include line which goes away when you comment out the include, that must mean the Mail.php is being included, but there is an error in it. I would advise you check your error log to find out what is wrong with Mail.php. @Mikhail could be on to something, you might find out what your error is by visiting Mail.php.

Also, if I understand correctly that Mail.php is in the same folder as the PHP file you showed above, then you shouldn't need to use include('./Mail.php'). include('Mail.php') should work just as well.

Upvotes: 1

Grant
Grant

Reputation: 2441

Looks like you are not including the file correctly:

<?php
if(!@file_exists('./Mail.php') ) {
    echo 'can not include';
} else {
   include('./Mail.php');
}
//rest of the code
 ?>

Use ../ to look recursively i.e. in the folder one level up for Mail.php.

Code should read:

include('../Mail.php')

Upvotes: 0

Mikhail
Mikhail

Reputation: 9007

Try visiting Mail.php directl, you may have some Apache securities enabled, which will reveal the issue.

Other issues may be due to permissions/ownership, etc.

Some debug information on would help.

Upvotes: 2

Related Questions