#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    3

    PHP with PEAR on Ubuntu - Ripping hair out


    Hey guys,
    Another migration to Linux issue with PEAR.

    I have installed pear. I have several mail scripts that look something like this:

    Code:
         require_once('Mail.php');
            include('mime.php');
    
            $sender = "no-reply@domain.com";
            $recipient = $email;
            $subject = "This is a test email subject"; 
            $text = 'This is a test text version.';   
           
           
            $html = '<html><body>And the HTML version.</body></html>'; 
            $crlf = "\n";
                $host = "smtp.sendgrid.net";
        $username = "foobar@foobar.com";
        $password = "foobar";
            $headers = array(
                            'From'          => $sender,
                            'Return-Path'   => $sender,
                            'Subject'       => $subject,
                            'host' => $host,
                'auth' => true,
                'username' => $username,
                'password' => $password,
                'port' => '25'
                            );
    
            // Creating the Mime message
            $mime = new Mail_mime($crlf);
    
            // Setting the body of the email
            $mime->setTXTBody($text);
            $mime->setHTMLBody($html);
    
            $body = $mime->get();
            $headers = $mime->headers($headers);
    
            // Sending the email
            $smtp =& Mail::factory('smtp',
            array ('host' => $host,
                'auth' => true,
                'username' => $username,
                'password' => $password,
                'port' => '25'
            ));
            $mail=$smtp ->send($recipient, $headers, $body);
             if (PEAR::isError($mail)) {
            echo($mail->getMessage());
        }

    On the Windows server this worked great. But now, I'm a little lost in PEAR with the Linux environment. I get this error:
    "Fatal error: Class 'Mail' not found in /home/vm/pear/share/pear/Mail.php on line 51"


    Line 51 of this PEAR file reads:
    class Mail_mail extends Mail {

    I have no idea what the heck I'm doing wrong. I have checked all the include paths to the best of my ability - which isn't much.

    Thanks for help guys
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    You probably need to update the include_path value in your php.ini file so that it includes your PEAR directory. If you run a phpinfo() command, what does it list for your include_path directive?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    3

    paths


    okay, i started to go down this path (no pun intended).
    rememeber, i came from windows so this is a little fuzzy to me.

    phpinfo path is:
    include_path .:/home/vm/pear/share/pear .:/home/vm/pear/share/pear

    i modified php.ini to cover all ground and do some trouble shooting:
    include_path = ".:/usr/share/php"
    include_path=".:/usr/local/php/pear/"
    include_path=".:/home/vm/pear/share/pear"

    ls of the reported path in phpinfo:
    vm@vmserver:/$ cd /home/vm/pear/share/pear
    vm@vmserver:~/pear/share/pear$ ls
    Archive mail.php mock.php PEAR peclcmd.php smtp.php
    Auth Mail.php Net PEAR5.php RFC822.php Structures
    Console mimePart.php null.php pearcmd.php sendmail.php System.php
    Mail mime.php OS

    vm@vmserver:/usr/share/PEAR$ ls
    Autoloader.php Dependency2.php Frontend.php REST.php
    Builder.php DependencyDB.php Installer RunTest.php
    ChannelFile Downloader Installer.php Task
    ChannelFile.php Downloader.php PackageFile Validate.php
    Command ErrorStack.php PackageFile.php Validator
    Command.php Exception.php Packager.php XMLParser.php
    Common.php FixPHP5PEARWarnings.php Registry.php
    Config.php Frontend REST
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    876
    Rep Power
    276
    I believe you can only have one "include_path" statement [not multiple]
    So, you would need to change this
    Code:
    include_path = ".:/usr/share/php"
    include_path=".:/usr/local/php/pear/"
    include_path=".:/home/vm/pear/share/pear"
    to this
    Code:
    include_path = ".:/usr/share/php:/usr/local/php/pear:/home/vm/pear/share/pear"
    in your php.ini file(s)
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    3

    still getting error


    Fatal error: Class 'Mail' not found in /home/vm/pear/share/pear/Mail.php on line 51
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    35
    Rep Power
    3

    any ideas


    look like the paths are all registering correctly.
    has this something to do within the Mail.php file?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    876
    Rep Power
    276
    in Debian6 linux [which is what Ubuntu is built from], the pear install/extensions are found in /usr/share/php.
    check in that folder and see if your Mail.php file is in there.
    If it is, I'd remove all the include_path statements except for include_path = ".:/usr/share/php".
    If it isn't then you may have to manually install the mail pkg in pear...using this command
    Code:
    pear install --alldeps mail
    and see if that fixes your issue.

    EDIT: Ok, I see from this command from above
    Code:
    ls of the reported path in phpinfo:
    vm@vmserver:/$ cd /home/vm/pear/share/pear
    vm@vmserver:~/pear/share/pear$ ls
    Archive mail.php mock.php PEAR peclcmd.php smtp.php
    Auth Mail.php Net PEAR5.php RFC822.php Structures
    Console mimePart.php null.php pearcmd.php sendmail.php System.php
    Mail mime.php OS
    that your pear install is in the /home/vm/pear/share/pear directory.
    The error is happening because the Mail.php file that your script is using is the wrong one.
    It is using the one inside your Mail subfolder [Mail/mail.php] which is also where your mime.php file is located.
    Try changing your include('mime.php'); to include('Mail/mime.php'); and see if that changes anything.
    Last edited by DonR; February 7th, 2013 at 12:47 PM.

IMN logo majestic logo threadwatch logo seochat tools logo