2011-03-16 127 views
5

我收到错误,如:如何检查PEAR是否安装在我的服务器上?

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

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

Fatal error: Class 'Net_SMTP' not found in /usr/local/lib/php/Mail/smtp.php on line 349

我的代码:

require_once 'Mail.php'; 

$from = "[email protected]>"; 

$to = "[email protected]>"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

$host = "mail.example.com"; 

$username = "me"; 
$password = "test"; 

$headers = array ('From' => $from, 
    'To' => $to, 
    'Subject' => $subject); 

$smtp = Mail::factory('smtp', 
    array ('host' => $host, 
    '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>"); 
} 

回答

19

,如果你有SSH访问,您可以登录并运行

which pear 

如果它安装它会打印的东西这样

/usr/bin/pear 
+4

这就是答案,选择它。 – 2012-07-16 13:23:47

13

使用此代码

require_once 'System.php'; 
var_dump(class_exists('System')); 

如果这是真的,梨安装。 更多信息:http://pear.php.net/manual/en/installation.checking.php

+1

'require_once'退出脚本出现致命错误,如果没有安装该模块。这就是为什么你应该首先检查模块是否安装(见上面的问题)。因此,这根本不是对上述问题的回答。 – feeela 2016-11-07 17:13:26

5

如果服务器在Ubuntu上,以下代码可能会有帮助。

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 

More info here

相关问题