Pear Mail “Unable to find class for driver smtp” C

2019-08-07 10:43发布

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>");
}

2条回答
Explosion°爆炸
2楼-- · 2019-08-07 10:59

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

查看更多
Root(大扎)
3楼-- · 2019-08-07 11:18

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)

查看更多
登录 后发表回答