Thursday, April 16, 2009

Ubuntu Install PEAR Mail for PHP / sending mail in Ubuntu via PHP

If you're getting some sort of 'php unable to load dynamic library' problem in PHP while trying to send email with PEAR/PHP on Ubuntu you'll probably need to do the following to install pear:

sudo apt-get install php-pear

sudo pear install mail

sudo pear install Net_SMTP

sudo pear install Auth_SASL

sudo pear install mail_mime



10 comments:

  1. Getting this error after:-

    pear install mail command

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/IcePHP.so' - /usr/lib/php5/20060613+lfs/IcePHP.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/ffmpeg.so' - /usr/lib/php5/20060613+lfs/ffmpeg.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/gmp.so' - /usr/lib/php5/20060613+lfs/gmp.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/php_mapscript.so' - /usr/lib/php5/20060613+lfs/php_mapscript.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/mhash.so' - /usr/lib/php5/20060613+lfs/mhash.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/ming.so' - /usr/lib/php5/20060613+lfs/ming.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/mssql.so' - /usr/lib/php5/20060613+lfs/mssql.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/odbc.so' - /usr/lib/php5/20060613+lfs/odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/pdo_dblib.so' - /usr/lib/php5/20060613+lfs/pdo_dblib.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/pdo_odbc.so' - /usr/lib/php5/20060613+lfs/pdo_odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/pdo_pgsql.so' - /usr/lib/php5/20060613+lfs/pdo_pgsql.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/pdo_sqlite.so' - /usr/lib/php5/20060613+lfs/pdo_sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/pgsql.so' - /usr/lib/php5/20060613+lfs/pgsql.so: cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/tidy.so' - /usr/lib/php5/20060613+lfs/tidy.so: cannot open shared object file: No such file or directory in Unknown on line 0
    Ignoring installed package pear/mail
    Nothing to install

    ReplyDelete
  2. strange. it all worked so smoothly for me. which version of PHP do you have installed? and you are running as sudo right?

    ReplyDelete
  3. Very usefull Thaks

    ReplyDelete
  4. Anonymous9:52 AM

    Worked great -- thanks.

    ReplyDelete
  5. Anonymous11:12 PM

    Brilliant, thanks!

    ReplyDelete
  6. Anonymous4:23 AM

    hey sudhir

    https://bugs.launchpad.net/ubuntu/+source/php5/+bug/541439
    this is what you have to do:
    dpkg -P php5-mhash

    Andrés Chandía

    ReplyDelete
  7. Anonymous9:36 PM

    Found this website on google. I am searching for a solution to alter the [ FRM:www-data ] header. This shows up even when using the -f option headers type. I a using php5's mail() funtions.
    mail($to,$from,$msg,$header,'-f xxx@myserver.com');

    ReplyDelete
  8. perfect, just what I needed!

    ReplyDelete
  9. It is showing this error :
    Deprecated: Assigning the return value of new by reference is deprecated in /opt/lampp/lib/php/Mail.php on line 55

    Deprecated: Assigning the return value of new by reference is deprecated in /opt/lampp/lib/php/Mail.php on line 135

    Strict Standards: Non-static method Mail::factory() should not be called statically in /opt/lampp/htdocs/test.php on line 22

    Warning: include_once(Net/SMTP.php) [function.include-once]: failed to open stream: No such file or directory in /opt/lampp/lib/php/Mail/smtp.php on line 157

    Warning: include_once() [function.include]: Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/bin/pear/') in /opt/lampp/lib/php/Mail/smtp.php on line 157

    Fatal error: Class 'Net_SMTP' not found in /opt/lampp/lib/php/Mail/smtp.php on line 159

    I apply the code in my file:

    $from,
    'To' => $to,
    'Subject' => $subject);
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    echo($mail->getMessage());
    } else {
    echo("Message successfully sent!");
    }
    ?>

    ReplyDelete
  10. Works great thanks

    ReplyDelete