Fatal error: Class 'Mail' not found in xampp \ php \ pear \ Mail \ mail.php

-4

I have an application with namespace defined. I use the class Mail / Mail.php and mime.php to send email. I have a scope problem. I include the email class within my scope. The error output is:

  

Fatal error: Class 'Mail' not found in \ xampp \ php \ pear \ Mail \ mail.php

My full class:

<?php

namespace esms;

require_once $_SERVER['DOCUMENT_ROOT'] . '/model/persistence/vo/esms_conta_vo.class.php';
//require_once $_SERVER['DOCUMENT_ROOT'] . "/model/service/sessao_service.class.php";

use esms\esms_conta_vo;

/**
 * Description of envia_email_service
 */
class envia_email_service {

//construtor
public function __construct() {

}

/**
 * @author WIllian ThyagoOP
 * Envia email
 * @param esms_conta_vo $esms_conta_vo vo
 * @param type $id id ovjeto vo
 * @param string $tipo tipo do email
 * @param int $id_cobranca id relacionado a cobrança
 */
public function envia_email(& $esms_vo, $tipo, $id_cobranca = 0) {
    if (! ($esms_vo instanceof esms_conta_vo)) {
        return NULL;
    }

    $id = $esms_vo->get_id();
    $nome = $esms_vo->get_nome();
    $email = $esms_vo->get_email();

    include_once("Mail/Mail.php");
    include_once("mime.php");

    $mime = new Mail_mime();

    //$headers["From"] = "[email protected]";
    $headers["From"] = "[email protected]";
    $headers["To"] = $email;
    $headers["Subject"] = "";
    $headers["Charset"] = "utf-8";
    $headers["Date"] = date("r");

    $params["host"] = "smtp.empresa.com.br";
    $params["port"] = "587";
    $params["auth"] = 'PLAIN';
    $params["username"] = "[email protected]";
    $params["password"] = "**********";

    if ($tipo == "bemvindo") {
        $headers["Subject"] = "[empresa] Seja bem-vindo";
        ob_start();
        include("/home/empresa/scripts/email_bemvindo.php");
        $html = ob_get_contents();
        ob_end_clean();
    }

    if ($tipo == "send") {
        $headers["Subject"] = "[E-SMS] Ative já sua conta!";
        ob_start();
//            require_once ($_SERVER['DOCUMENT_ROOT'] . '/emails/registro/email.php');
        $_POST['email'] = $email;
        $_POST['nome'] = $nome;
        require_once ($_SERVER['DOCUMENT_ROOT'] . "/email.php");
        $html = ob_get_contents();
        ob_end_clean();
        // Anexa boleto em PDF
        //$mime->addAttachment("/home/empresa/pdfs/".$pagamentos_row['id_transacao'].".pdf");
    }

    if ($tipo == "cobranca") {
        $headers["Subject"] = "[empresa] Remessa de Boleto Bancário";
        ob_start();
            include("/home/empresa/scripts/email_cobranca.php");
        $html = ob_get_contents();
        ob_end_clean();
        // Anexa boleto em PDF
        //$mime->addAttachment("/home/empresa/pdfs/".$pagamentos_row['id_transacao'].".pdf");
    }

    if ($tipo == "cobranca_aviso_venc") {
        $headers["Subject"] = "[empresa] Aviso de vencimento";
        ob_start();
        include("/home/empresa/scripts/email_cobranca_avisovencimento.php");
        $html = ob_get_contents();
        ob_end_clean();
    }

    if ($tipo == "cobranca_aviso_pagaberto") {
        $headers["Subject"] = "[empresa] Aviso de pagamento em aberto";
        ob_start();
        include("/home/empresa/scripts/email_cobranca_avisopagaberto.php");
        $html = ob_get_contents();
        ob_end_clean();
    }

    if ($tipo == "senha") {
        $headers["Subject"] = "[empresa] Reenvio de senha";
        ob_start();
        include("/home/empresa/scripts/email_senha.php");
        $html = ob_get_contents();
        ob_end_clean();
    }

    $mime->setTXTBody(strip_tags($html));
    $mime->setHTMLBody($html);
    $body = "";
    $body = $mime->get();
    $headers = $mime->headers($headers);

    $mail_object = & Mail::factory("smtp", $params);
    $send = $mail_object->send($email, $headers, $body);

    if (PEAR::isError($send))
        return false;
    else
        return true;
}

public function envia_email_c($de, $para, $assunto, $mensagem) {
    include_once("Mail.php");
    include_once("Mail/mime.php");

    $from = $de;
    $to = $para;
    $subject = $assunto;
    $body = $mensagem;

    $host = "smtp.empresa.com.br";
    $username = "[email protected]";
    $password = "*******";

    $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
    $smtp = Mail::factory('smtp', array('host' => $host, 'auth' => 'PLAIN', 'username' => $username, 
        'password' => $password, 'starttls' => false, 'debug' => false));
    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail))
        return false;
    else
        return true;
}

public function envia_email_h($de, $para, $assunto, $mensagem) {
    include_once("Mail.php");
    include_once("Mail/mime.php");

    $email = $para;
    $headers["From"] = $de;
    $headers["To"] = $para;
    $headers["Subject"] = $assunto;
    $headers["Charset"] = "utf-8";
    $headers["Date"] = date("r");

    $params["host"] = "smtp.empresa.com.br";
    $params["port"] = "587";
    $params["auth"] = true;
    $params["username"] = "[email protected]";
    $params["password"] = "******";

    ob_start();
    include("/home/empresa/scripts/email_timbrado.php");
    $html = ob_get_contents();
    ob_end_clean();

    $mime = new Mail_mime();
    $mime->setTXTBody(strip_tags($html));
    $mime->setHTMLBody($html);
    $body = $mime->get();
    $headers = $mime->headers($headers);

    $mail_object = & Mail::factory("smtp", $params);
    $send = $mail_object->send($email, $headers, $body);

    if (PEAR::isError($send)) {
        //echo $send->getMessage();
        return false;
    } else {
        return true;
    }
}

}
    
asked by anonymous 29.12.2015 / 13:06

1 answer

0

Following the tips of friends we can solve. Thank you all.

$mime = new \Mail_mime();
    
29.12.2015 / 14:50