lmaster Posted November 25, 2008 Share Posted November 25, 2008 Hello all I installed the mail and net_smtp PEAR modules though i am getting the following error when I type c:\php mailer1.php PHP Fatal error: Call to undefined method PEAR_Error::send() in C:\php\mailer1. php on line 24 This is my script: <?php require_once "Mail.php"; $from = "Lawrence Master <taxandaccountingassoc@gmail.com>"; $to = "Lawrence Master <taxandaccountingassoc@gmail.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://smtp.gmail.com"; $username = "taxandaccountingassoc@gmail.com"; $password = "XXXXX"; $port = "465"; $headers = array ('From' => $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("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> I would appreciate any help Thanks Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/ Share on other sites More sharing options...
btherl Posted November 25, 2008 Share Posted November 25, 2008 The error message is saying that $smtp is a pear error, meaning the Mail::factory() call failed. Add this code after that call: if (PEAR::isError($smtp)) { echo("<p>" . $smtp->getMessage() . "</p>"); } Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-698273 Share on other sites More sharing options...
lmaster Posted November 25, 2008 Author Share Posted November 25, 2008 Hi, thanks for trying to help, I am still getting the same error, I though I already had that code snippet at the end? Any other ideas? Thanks, Lawrence Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-698795 Share on other sites More sharing options...
btherl Posted November 26, 2008 Share Posted November 26, 2008 You need the code snippet with $smtp as well, not just $mail. Both can be pear errors if they fail. Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-699139 Share on other sites More sharing options...
DeanWhitehouse Posted November 26, 2008 Share Posted November 26, 2008 Do all hosts even support PEAR? Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-699140 Share on other sites More sharing options...
btherl Posted November 26, 2008 Share Posted November 26, 2008 You can install the pear libs if your host doesn't have them pre-installed. Hosts will typically only have common pear libs installed, if any, but you can install your own. Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-699143 Share on other sites More sharing options...
lmaster Posted November 26, 2008 Author Share Posted November 26, 2008 btherl, Thanks for your help. Unfortunately, adding that those three lines simply shifted where it hangs by three lines further down, here is my complete script with your addition and the output: <?php require_once "Mail.php"; $from = "Lawrence Master <taxandaccountingassoc@gmail.com>"; $to = "Lawrence Master <taxandaccountingassoc@gmail.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://smtp.gmail.com"; $username = "taxandaccountingassoc@gmail.com"; $password = "XXXX"; $port = "465"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); if (PEAR::isError($smtp)) { echo("<p>" . $smtp->getMessage() . "</p>"); } $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> C:\php>php mailer1.php <p>Unable to find class for driver smtp</p>PHP Fatal error: Call to undefined m ethod PEAR_Error::send() in C:\php\mailer1.php on line 27 Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-699453 Share on other sites More sharing options...
btherl Posted November 27, 2008 Share Posted November 27, 2008 Actually the new code tells you why it's not working. It gives this important message: "<p>Unable to find class for driver smtp</p>" Here's the code that generates the error: function &factory($driver, $params = array()) { $driver = strtolower($driver); @include_once 'Mail/' . $driver . '.php'; $class = 'Mail_' . $driver; if (class_exists($class)) { $mailer = new $class($params); return $mailer; } else { return PEAR::raiseError('Unable to find class for driver ' . $driver); } } So basically it attempted to include "Mail/smtp.php" and check for the Mail_smtp class, but was unable to find it. So either Mail/smtp.php doesn't exist, or including it did not define the Mail_smtp class. Can you see the Mail/smtp.php file? Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-699884 Share on other sites More sharing options...
lmaster Posted November 27, 2008 Author Share Posted November 27, 2008 MAKING PROGRESS, Yes it was a file/directory placement issue, I'm past that, BUT NOW I AM HAVING PROBLEMS WITH SSL, I followed the advice on this page, but it still does not work: http://forum.uniformserver.com/index.php?showtopic=1378 C:\php\PEAR>php mailer1.php PHP Warning: PHP Startup: openssl: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=1 PHP compiled with module API=20050922, debug=0, thread-safety=1 These options need to match in Unknown on line 0 <p>Failed to connect to ssl://smtp.gmail.com:465 [sMTP: Failed to connect socket : Unable to find the socket transport "ssl" - did you forget to enable it when y ou configured PHP? (code: -1, response: )]</p> C:\php\PEAR> Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-700603 Share on other sites More sharing options...
btherl Posted November 28, 2008 Share Posted November 28, 2008 Does phpinfo() show that ssl is enabled? Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-700698 Share on other sites More sharing options...
lmaster Posted November 28, 2008 Author Share Posted November 28, 2008 It doesn't look like it, what's the correct procedure? PHP Version 5.1.4 System Windows NT 6RTUWESQ 5.1 build 2600 Build Date May 4 2006 10:30:29 Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" Server API Apache 2.0 Handler Virtual Directory Support enabled Configuration File (php.ini) Path C:\php\php.ini PHP API 20041225 PHP Extension 20050922 Zend Extension 220051025 Debug Build no Thread Safety enabled Zend Memory Manager enabled IPv6 Support enabled Registered PHP Streams php, file, http, ftp, compress.zlib Registered Stream Socket Transports tcp, udp Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.* Zend logo This program makes use of the Zend Scripting Language Engine: Zend Engine v2.1.0, Copyright © 1998-2006 Zend Technologies Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-700973 Share on other sites More sharing options...
lmaster Posted November 29, 2008 Author Share Posted November 29, 2008 All, its fixed... It ended up being a bad install of PHP... I simply got the latest binaries and extracted into the PHP folder, and put back my php.ini file and it works like a charm now... I guess the distribution I got off a book had dll's that were corrupted and mismatched. Thank you everybody that tried to help!! Quote Link to comment https://forums.phpfreaks.com/topic/134143-call-to-undefined-method-pear_errorsend-help/#findComment-701809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.