Pear Mail “Unable to find class for driver smtp” Cannot find file, that is there

谁说胖子不能爱 提交于 2019-12-24 07:26:20

问题


My VPS is running CentOS 5.3. I have installed pear, Mail, and Net_Mail. When I try to send mail, I get, "Unable to find class for driver smtp". I looked through Mail.php, found that I need a 'Mail/smtp.php' inside my pear directory, which there is. I verified the php include directory, and I reset all of the perms to apache via chown. I checked chmod, and they are all 644.

My code:

    $from = "Admin <admin@myemail.com>";
$to = "New User <".$email.">";
$subject = "Welcome to MyEmail!";
$body = "Thanks for choosing <MyEmail>! We strive to provide 24/7 email service and support. If you have ANY issues, concerns, etc, please reply to this email, or simply compose a new one to: myemail@email.com !";
$host = "localhost";
$username = "username";
$password = "password"; 
$headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
$smtp = Mail::factory('smtp',
    array ('host' => $host,
    '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>");
}

回答1:


The code as you gave it works here, when adding require_once 'Mail.php'; at the beginning.

What md5 hash has the Mail/smtp.php file on your server? Does it contain a class Mail_smtp line?

Here it is: 479aa21ec86e63e629db646ed292b142 (via md5sum /usr/share/php/Mail/smtp.php)




回答2:


I ran this this same issue, the apache user could not read the Mail/smtp.php file and was unable to load the driver.

Check the pear path with pear config-get php_dir

Go to that directory and check if Mail.php is there, check if the subdirectory Mail/ is there with a smtp.php file inside.

Check that the apache user, or php user can read those files: su -s /bin/sh apache -c "ls -la /[pathtopear]/Mail"

In my case, Mail and Net directories were only readable by root



来源:https://stackoverflow.com/questions/24337277/pear-mail-unable-to-find-class-for-driver-smtp-cannot-find-file-that-is-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!