i have a problem with include_path.
i have no access to my php.ini and i used :

ini_set('include_path', ini_get('include_path'));

on top of my code but it didn't change
i used

echo __FILE__;

i saw the direction of the file was :
D:\Domains\mysite.com\wwwroot\mailer.php
then i used :

ini_set('include_path', ".;D:\Domains\mysite.com\wwwroot/pear/PEAR/");

but it can't find pear class in socket.php when it exit.
it is the same about other packages and they can't find pear class in a php file.
in socket.php .. pear.php is required like this :

require_once 'PEAR.php';

error :

Fatal error: Class 'PEAR' not found in D:\Domains\mysite.com\wwwroot\pear\PEAR\Net\Socket.php on line 47

if you can please help.
thanks in advance.

    salsabil;10966158 wrote:

    i used :

    ini_set('include_path', ini_get('include_path'));

    on top of my code but it didn't change

    Uh... did you read what you just wrote? You're trying to set the value of include_path equal to the value of include_path... and you're wondering why it didn't change? 😕

    salsabil;10966158 wrote:

    i used :

    ini_set('include_path', ".;D:\Domains\mysite.com\wwwroot/pear/PEAR/");

    While I believe the forward slash is correctly interpreted in just about any path on Windows, you should still be consist in which path separator you use. So... pick one - use forward slashes or backslashes, but not both.

      i installed pear in my computer and it works as well.
      but in my host it is going to be never working :quiet:
      my host use windows.
      i had befor trying forward slashes and i used it again too but no change and still the error :

      Fatal error: Class 'PEAR' not found in D:\Domains\mydomain.com\wwwroot\pear\PEAR\Net\Socket.php on line 47

      shows its power as well. lool

      any other idea ?

        my pear is located here :
        D:\Domains\mysite.com\wwwroot\pear\PEAR\PEAR.php

        please remove my website name in my previous post. thanks

          Okay, so can you show us what you changed the ini_set() line to? Also, did you make sure to call ini_set() before you do any other include/require()'ing?

            it is on top of my php code like this :

            <?php
            ini_set('include_path', ".;D:/Domains/mydomain.com/wwwroot/pear/PEAR/". PATH_SEPARATOR . ini_get('include_path'));

              Not sure what the problem is. I removed my local PEAR directory from the include_path directive and instead used the ini_set() line you have, and when I did require "Net/Socket.php", everything worked without error.

              Can you show us more of the code of the beginning of mailer.php where you're include/require()'ing stuff?

              Also, after the ini_set() line, what does this:

              var_dump(ini_get('include_path'));

              output?

                it outputs :
                string(57) ".;D:/Domains/mydomain.com/wwwroot/pear/PEAR/;.;C:\php5\pear"

                my php code :

                <?php 
                ini_set('include_path', ".;D:/Domains/mydomain.com/wwwroot/pear/PEAR/". PATH_SEPARATOR . ini_get('include_path'));
                
                // Include the Mail package
                
                require "Mail.php";
                // Identify the sender, recipient, mail subject, and body
                $sender = "email@gmail.com";
                $recipient = "email@gmail.com";
                $subject = "Thank you for registering";
                $body = "Thank you for registering!";
                
                // Identify the mail server, username, password, and port
                $server = "ssl://smtp.gmail.com";
                $username = "email@gmail.com";
                $password = "password";
                $port = "465";
                
                // Setup the mail headers
                $headers = array(
                  "From"    => $sender,
                  "To"      => $recipient,
                  "Subject" => $subject
                );
                
                // Configure the mailer mechanism
                $smtp = Mail::factory("smtp",
                  array(
                    "host"     => $server,
                    "username" => $username,
                    "password" => $password,
                    "auth"     => true,
                    "port"     => 465
                  )
                );
                
                // Send the message
                $mail = $smtp->send($recipient, $headers, $body);
                
                if (PEAR::isError($mail)) {
                  echo ($mail->getMessage());
                } else {
                  echo("Success!");
                }    
                
                ?>

                  I'd recommend always using forward slashes, /, in paths even on windows. Backslashes comes with their own set of troubles

                  echo '<pre>';
                  echo "path\to\new\file.txt";
                  echo "\n\n";
                  echo "path\\to\\new\\file.txt";
                  echo "\n\n\n";
                  echo 'path\to\new\file.txt';
                  echo "\n\n";
                  echo 'path\\to\\new\\file.txt';
                  echo '</pre>';
                  

                  Other than that, why the seemingly double install of pear, and why does one of the include paths go to .../pear while the other goes to .../pear/PEAR?
                  And, looking at my windows installation, it should be the former. But, find out for yourself. The missing class PEAR is found in a file called PEAR.php, so all you need to do is locate this file and add its path to the include path. Since the default is C:/php5/pear, iirc, the first place I'd look would be D:/Domains/mydomain.com/wwwroot/pear/ (rather than D:/Domains/mydomain.com/wwwroot/pear/PEAR).

                    I have just one pear installed in the folder : pear
                    i've used .htaccess to set a password on it

                    the next PEAR is for pear itself.

                    so D:/Domains/mydomain.com/wwwroot

                    the folder that i've created is : /pear
                    pear folder : /PEAR

                    this is the location of my PEAR.php :

                    D:\Domains\mysite.com\wwwroot\pear\PEAR\PEAR.php

                    thank you.

                    any other idea ?

                      Write a Reply...