Jump to content

require_once path not found


rocky48

Recommended Posts

I am trying to used phpmailer and falling at the first hurdle!

 

I get the following error when running this script:

Warning: require_once(../class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in C:\websites\Test\test_sendmail_basic.php on line 9

Fatal error: require_once() [function.require]: Failed opening required '../class.phpmailer.php' (include_path='.;c:\php\includes') in C:\websites\Test\test_sendmail_basic.php on line 9

 

Line 9 is: require_once('../class.phpmailer.php');

 

I have checked my C:\php\includes folder and it contains the file.

 

I double checked my include path in php.ini and it is: include_path = ".;c:\php\includes"

 

I just can't see whats wrong!

 

Can anyone help!

 

Thank you!

Link to comment
Share on other sites

I'm no expert on this, but isn't your path supposed to use a colon ":" to separate multiple path values?  You have  dot semicolon as your first entry and then your second path that you referred to.  I'm wondering if the semi is preventing it from being used.

Link to comment
Share on other sites

the ".." means the parent folder - it is a common technique to make a relative path (as opposed to an absolute one).  The single dot refers to the current directory - something that would mean "check the current folder before looking elsewhere" in your situation.

 

So - if you are using windows, then perhaps your reference to the filename should use a backslash instead of the forward slash you have specified.  Just a WAG...

Link to comment
Share on other sites

 

 

I have checked my C:\php\includes folder and it contains the file.

So you have placed class.phpmailer.php in the includes folder? If that is the case then use

require_once 'class.phpmailer.php';

The above lines should still worlk if you place that file in C:\websites\Test\ too

Link to comment
Share on other sites

I have tried

 

require_once 'class.phpmailer.php';

I have also added the file to c:\websites\Test as well, but it still does not work!

I found a duplicate copy of php.ini in another folder so changed them both to:

 

include_path = "c:\php\includes"

But it still comes up with the same error message.

I noticed that the error still shows the syntax that I had before I changed it??

 

require_once(../class.phpmailer.php)

and

'../class.phpmailer.php' (include_path='.;c:\php\includes')

Does it not read the lines from the script you are running?

Is there a cache that is remembering the locations?

If so can this be cleared?

 

I have cleared the browsers history cache and that has no effect.

 

This is getting anoying!

Link to comment
Share on other sites

Here is a simple test on my CentOS machine, you can apply the same principle on windows one.

The default web root directory on CentOS/RedHat/Fedora is /var/www/html. 

In the html folder I've created my current directory named swiftmailer.: /var/www/html/swiftmailer with testing php file include.php

I'm using swiftmailer for the test, however, no problem to use phpmailer as well.

 

The downloaded library I put it for the test inside /var/www directory, so the full path is: /var/www/swift-5.0.3

 

I open up the php.ini file and make next changes: 

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;
include_path = ".:/var/www"

  Then include "swift_required.php" to testing file named include.php

 

include.php

<?php

echo (include 'swift-5.0.3/lib/swift_required.php') ? 'TRUE' : 'FALSE';


RESULT: TRUE

If I change the included path to include_path = ".:/var"

 

Result:

 

 

Warning: include(swift-5.0.3/lib/swift_required.php): failed to open stream: No such file or directory in /var/www/html/swiftmailer/include.php on line 3

Warning: include(): Failed opening 'swift-5.0.3/lib/swift_required.php' for inclusion (include_path='.:/var') in /var/www/html/swiftmailer/include.php on line 3

FALSE

 

That's all, there is nothing complicated, just doulbe check the paths. It should be work on windows as well.

 

Don't forget to restart apache after you made some changes in php.ini file!

Link to comment
Share on other sites

I have  run the test script based on your suggestion but it does not find the file and therefore reports FALSE.

 

One observation i have made is that your PHP folder is a sub folder of your www folder, where as mine is in a folder off the root of C:.

Does this make any difference?

Apart from this script all other PHP scripts work OK!

Link to comment
Share on other sites

If you have in your ini file include_path = ".;c:\php\includes" and your class.phpmailer.php file is located at c:\php\includes\class.phpmailer.php then what you would want to write in your PHP code is simply:

require_once 'class.phpmailer.php';
Essentially you need to make sure that the value you give to require_once (or include, etc) combined with one of the paths in your include_path directive points to a valid file. So, given your script is located in C:\websites\Test\ when you do require_once 'class.phpmailer.php'; with include_path=".;c:\php\includes" PHP will:
  • Does c:\website\test\class.phpmailer.php exist? yes/no
  • Does c:\php\includes\class.phpmailer.php exist? yes/no
The first one of those to be answered 'yes' is the file that is included. If none are true, you get your error.

 

As mentioned before, you need to make sure you restart apache when making changes to your php.ini file. Changes made are not seen until a restart is done. Also the output of phpinfo() will tell you exactly which php.ini file to be editing and what the current configuration values are incase there are multiple files and you are unsure which to use.

Link to comment
Share on other sites

One observation i have made is that your PHP folder is a sub folder of your www folder, where as mine is in a folder off the root of C:.

Does this make any difference?

 

No!

[root@lxc1]# mkdir -p /includes

[root@lxc1]# mv /var/www/Swift-5.0.3/ /includes/

[root@lxc1]# ls /includes/

Swift-5.0.3

// php.ini
 
include_path = ".:/includes"

[root@lxc1]# /etc/init.d/httpd restart

//include.php

<?php

echo (include 'Swift-5.0.3/lib/swift_required.php') ? 'TRUE' : 'FALSE';

Result: TRUE




 

If you have in your ini file include_path = ".;c:\php\includes" and your class.phpmailer.php file is located at c:\php\includes\class.phpmailer.php then what you would want to write in your PHP code is simply:

 

This could go wrong on Linux, not sure for Windows.

 

@rocky48, can you post the link where you downloaded phpmailer. I wanna see the structure.

Link to comment
Share on other sites

I downloaded it from this site:

http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list.

 

I am really baffled why this is not working.

I have checked the php.ini file numeous times and even looked at httpd.conf.

 

I have even added c:\php\includes into my windows path environment settings.

 

Any other ideas would be appreciated!

Link to comment
Share on other sites

I do believe someone using windows environment would help here.

 

Here is all commands under my CentOS-box.

// go to includes directory
[root@lxc1]# cd /includes

// download the library
[root@lxc1 includes]# wget http://phpmailer.apache-extras.org.codespot.com/files/PHPMailer_5.2.4.tgz

// unzip it
[root@lxc1 includes]# tar -zxvf PHPMailer_5.2.4.tgz

// delete the tar file
rm -f PHPMailer_5.2.4.tgz

// list all files/directories in to /includes
[root@lxc1 includes]# ls
PHPMailer_5.2.4


[root@lxc1 includes]# ls PHPMailer_5.2.4/
changelog.txt
class.phpmailer.php
class.pop3.php  
class.smtp.php
docs
docs.ini  
examples
extras
language
LICENSE
README
test  
test_script

// php.ini 

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;
include_path = ".:/includes"

// restart the web service
[root@lxc1 includes]# /sbin/service httpd restart

// open up index.php 
 
[root@lxc1 includes]# vim /var/www/html/pdo/index.php

<?php
echo (include 'PHPMailer_5.2.4/class.phpmailer.php') ? 'TRUE' : 'FALSE';

Result: TRUE

Link to comment
Share on other sites

if would help if you posted your current error message and the current code. the error may have changed slightly and would provide a clue as to the current/continuing problem.

 

edit: as to your code change not being reflected in the error above in the thread, that's a sign that the code running isn't the code you are changing. you either have multiple lines trying to include/require this class file and are not changing all occurrences or you have multiple main files and are changing the wrong one or not saving it to the right folder.

Link to comment
Share on other sites

Hi Mac

The error message has not changed from the one that I posted at the beginning of the thread.

I am writing this on my iPad so can't post my code tonight, will send tomorrow.

I only require the class.phpmailer.php once in my script.

Link to comment
Share on other sites

just to summarize -

 

1) using require_once '../class.phpmailer.php'; is specifying a relative path and does not use the include_path setting. the include_path is mentioned in the error because it's a generic error message. a relative or an absolute path requires (no pun intended) that the file be at the resulting relative or absolute path.

 

2) the suggestion to use require_once 'class.phpmailer.php'; is based your statement that the class.phpmailer.php file is present in the folder mentioned in the include_path setting. this should work, except that you stated the ../ relative part of the path is still being shown in the error message.

 

3) if the error still mentions the ../ relative part of the path for the file, your problem is that the changes you are making to your main file are not being used. your file either got saved with a .php.txt extension and didn't actually replace the original or you have multiple files at different locations and are editing the wrong one or you are not saving the file into the correct location in your document root folder and an older version is being used.

Link to comment
Share on other sites

Hi Mac

 

I have positively eliminated any other php.ini files and only have one in c:\php.

Also I have checked apache httpd.conf and it points to C:/php (PHPIniDir "C:/php).

The file class.phpmailer.php is in the C:\php\includes folder, along with all the other files associated with phpmailer, that I downloaded.

 

Here is the code that I am trying to run:

<html>
<head>
<title>PHPMailer - Sendmail basic test</title>
</head>
<body>

<?php

require_once '\class.phpmailer.php';

$mail             = new PHPMailer(); // defaults to using php "mail()"

$mail->IsSendmail(); // telling the class to use SendMail transport

$body             = file_get_contents('contents.html');
$body             = preg_replace('/[\]/','',$body);

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

//$address = "whoto@otherdomain.com";
//$mail->AddAddress($address, "John Doe");

include("connect_mailer.php");
doDB5();
echo "connected to database?";

	if (mysqli_connect_errno()) {
		//if connection fails, stop script execution
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	} else {
		//otherwise, get emails from subscribers list
		$sql = "SELECT email FROM subscribers";
		$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));

		//create a From: mailheader
		$mailheaders = "From: webmaster@1066cards4u.co.uk>";

		//loop through results and send mail
		while ($row = mysqli_fetch_array($result)) {
			$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
                $mail->MsgHTML($body);
                $mail->AddAddress($row["email"]);
                $mail->AddAttachment("images/phpmailer.gif");      // attachment
                $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
		}
		
	}


while ($row = mysql_fetch_array ($result)) {
  
echo "ready to send";
  if(!$mail->Send()) {
    echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . '<br />';
  } else {
    echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "@", $row["email"]) . ')<br />';
  }
  // Clear all addresses and attachments for next loop
  $mail->ClearAddresses();
  $mail->ClearAttachments();
}
?>

</body>
</html>

The current error message is:

 

Warning: require_once(../class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in C:\websites\Test\test_sendmail_basic.php on line 9

Fatal error: require_once() [function.require]: Failed opening required '../class.phpmailer.php' (include_path='.;\c:\php\includes') in C:\websites\Test\test_sendmail_basic.php on line 9

 

I have also puta copy of the class.phpmailer.php file in the test folder, but that made no difference.

Link to comment
Share on other sites

So, comparing with my include_path (for windows environment) your path is different. See, the backslash in front of "C":

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

// yours
Failed opening required '../class.phpmailer.php' (include_path='.;\c:\php\includes')

This is the error of your first posting:

Failed opening required '../class.phpmailer.php' (include_path='.;c:\php\includes')

No need to use a backslash here:

require_once '\class.phpmailer.php';
Link to comment
Share on other sites

the leading \ (windows) or / (non-windows or windows - php converts / to \ on windows) refers to the root of the current disk. no one here suggested or showed using require_once '\class.phpmailer.php';

 

as to the error message, when i try require_once '\class.phpmailer.php';, i get messages referring to '\class.phpmailer.php'; i'm guessing your version of php has a bug (they have had several concerning the include/require _once.. functions.) see if it works correctly using the suggested require_once 'class.phpmailer.php';

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.