1
votes

I am getting these errors:

PHP Fatal error: main() [function.require]: Failed opening required '/usr/share/pear/Mail.php' (include_path='.:/var/www/vhosts/xxx.net/httpdocs/protected/modules/rbam/models:/var/www/vhosts/xxx.net/httpdocs/protected/extensions/translations/components:/var/www/vhosts/xxx.net/httpdocs/protected/extensions/runactions/components:/var/www/vhosts/xxx.net/httpdocs/protected/components:/var/www/vhosts/xxx.net/httpdocs/protected/models:/usr/share/pear:') in /var/www/vhosts/xxx.net/httpdocs/protected/components/MailComponent.php on line 70

First of all, the include statement is not in line 70 of my MailComponent.php, it is on line 3 (but MailComponent.php has exactly 69 lines so that may just be a bug in the way PHP reports the error)

require_once '/usr/share/pear/Mail.php'; 

The file /usr/share/pear/Mail.php is right there, at /usr/share/pear/Mail.php, it belongs to root but it has read permissions to everybody; and as you can see /usr/share/pear IS in the include path. And furthermore, this used to work until recently and I haven't touched it.

So what may be the issue?!?!?

EDIT: I think it's something related to the fact that the folder where the included file is is outside the httpdocs folder, but why so and how do I allow it?

(I'm also puzzled at that main(), I don't have any such method anywhere; I'm using Yii which does have a couple of main() methods here and there (just grepped) though the error is reported to be in my code, allegedly in my MailComponent.php where the include_once is).

<?php

require_once '/usr/share/pear/Mail.php'; // PEAR Mail
require_once '/usr/share/pear/Mail/mime.php'; // PEAR Mail_mime

class MailComponent extends CApplicationComponent {

    public $defaultHeaders=array();
    public $debugUsers=false;
    public $debugAdmins=false;
    public $debugEmail='[email protected]';
    public $backend='mail';

    public function sendMail($address, $subject, $body, $headers=array(), $isadmin=false) {

        $actualheaders=array_merge($this->defaultHeaders, $headers);
        $actualheaders['Subject']=$subject;

        $mail = new Mail_mime(array(
            "text_charset" => "utf-8",
            "html_charset" => "utf-8",
            "eol" => "\n"
        ));

        $mail->setTxtBody($body);

        if (($isadmin && $this->debugAdmins) || (!$isadmin && $this->debugUsers)) {
            $address=str_replace('@','_AT_',$address)." <".$this->debugEmail.">";
            //$address=$this->debugEmail;
        }
        $actualheaders['To']=$address;
        $headersencoded=array();
        foreach ($actualheaders as $header=>$value) {
            $headersencoded[$header]=$mail->encodeHeader($header, $value, "utf-8", "quoted-printable");
        }
        //$to=$mail->encodeHeader('To',$address,"utf-8", "quoted-printable");
        $to=$headersencoded['To'];
        $msg=@$mail->get();
        $actualheaders=$mail->headers($headersencoded);
        @$factory=& Mail::factory($this->backend);
        @$ret=$factory->send($to,$actualheaders,$msg);
        if ($ret instanceof PEAR_Error) Yii::log('ERROR SENDING MAIL TO '.$to, 'error');
        return $ret;     
    }

    public function notifyAdmins($role, $area, $subjectcode, $bodycode, $params=array()) {
        $admins=Yii::app()->authManager->getUsers($role);
        $users=array();
        foreach ($admins as $userid) {
            $user=User::model()->findByPk($userid);
            if ($user===null) continue;
            if ($user->current_area_id!=$area->id) continue;
            if ($user->email===null || ($email=trim($user->email))=='') continue;
            $lang=$user->preferredLanguage;
            $params['{CHANNEL_NAME}']=I::tattr($area->partialRoot, 'menu.home', $lang);
            $params['{USER}']=$user->getActualDisplayName();
            $subject=I::t($subjectcode,$lang,$params);
            $body=I::t($bodycode,$lang,$params);
            $this->sendMail($email, $subject, $body, array(), true);
        }
    }

}

?>
1
We need the code of MailComponent.phpNik Drosakis
The main() function is the function of the PHP interpreter itself. It is having problems even parsing or executing your code.Broncha
PHP was developed by some guys who really knew what they were doing. I suspect their error messages can be bogus? Its us who have to understand things better.Hanky Panky
@Broncha I think if it was a parse problem I would get a different error wouldn't Imatteo
@HankyPankyㇱ: "PHP was developed by some guys who really knew what they were doing"????????????? Is it possible that you are on hard drugs?Lightness Races in Orbit

1 Answers

0
votes

Are you sure the correct version of the file "MailComponent.php" is being loaded? If, as you say, this file has 69 lines, and the error appears on line 70, I'd start by suspecting the error is referring to some other MailComponent.php file.