在PHPMailer新版本中找不到PHPMailer

时间:2017-11-18 21:20:57

标签: php phpmailer

以下代码使用PHP:

class Email
{
    private $mail,$to,$subject,$body;
    function __construct()
    {
        require_once "phpmailer1/src/PHPMailer.php";
        require_once "phpmailer1/src/SMTP.php";
        require_once "phpmailer1/src/POP3.php";
        $this->mail = new PHPMailer(true);
        $this->mail->isSMTP();
        $this->mail->Host = "smtp.gmail.com";
        $this->mail->Username = "emailaddress";
        $this->mail->Password = "password";
        $this->mail->SMTPSecure = "tls";
        $this->mail->Port = 587;
        $this->to = "0";
        $this->subject = "0";
        $this->body = "0";
        $this->mail->SMTPAuth = true;
        $this->mail->setFrom("new address email","hello");
        $this->mail->CharSet = "utf-8";
        $this->mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
        );
    }
    function ToEmail($getmail)
    {
        $this->to = $getmail;
    }
    function SubjectMail($submail)
    {
        $this->subject = $submail;
    }
    function BodyMail($bodymail)
    {
        $this->body = $bodymail;
    }
    function Send()
    {
        if($this->to != "0" && $this->subject != "0" && $this->body != "0")
        {
            $this->mail->addAddress($this->to,"hello");
            $this->mail->subject = $this->subject;
            $this->mail->msgHTML($this->body);
            if($this->mail->send())
            {
                echo "Email Send";
            }
            else
            {
                echo "Email Not Send";
            }
        }
        else
        {
            echo "230";
        }
    }
};

我想使用PHPMailer的新版本,但是当我想要运行它时,我会看到

  

致命错误:未捕获错误:类' PHPMailer'在C:\ xampp \ htdocs \ xampp \ khunehyab \ email \ mainemail.php中找不到:13堆栈跟踪:#0 C:\ xampp \ htdocs \ xampp \ khunehyab \ email \ mainemail.php(69):Email-> __construct()#1 {main}抛出我该怎么办?请帮助我,我的PHPMailer是v6.0.1

1 个答案:

答案 0 :(得分:0)

您需要使用PHPMailer\PHPMailer\PHPMailer的完全限定类名(FQCN),或将其导入到您的文件名顶部use PHPMailer\PHPMailer\PHPMailer;的命名空间中。