首页 > 解决方案 > 出现致命错误:无法重新声明类 PHPMailer\PHPMailer\PHPMailer

问题描述

    <?php
    /**
     * send mail short leave
     */
    require_once("../../hrm/Emails/smtp/PHPMailer.php");
      require_once("../../hrm/Emails/smtp/SMTP.php");
        
    class SendMailsleave
    {
        private $as;
        
        function __construct($u_id)
        {
            $this->as = $u_id;
            //echo $this->as;
            $this->SendMail();
    
        }
    
        public function SendMail()
        {
    
            //if somehow admin email failed , as a redirect.
            $sendto="noreply@caddcentre.lk";
            $senn="defaultcadd";
            include("../connection.php");
            require '../Emails/smtp/PHPMailer.php';
    
    $mail = new PHPMailer();
    
    $mail->IsSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'box894.bluehost.com'; 
    $mail->Host = 'mail.ectc.lk'; 
    
                    // Specify main and backup server
    $mail->Port = 26;                                // Set the SMTP port
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'noreply@ectc.lk';                // SMTP username
    $mail->Password = 'Admin@2020';     // SMTP password
    //$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    
    $mail->From = 'noreply@ectc.lk';
    $mail->FromName = 'ECTC HRM System';
    
    
    $mail->AddAddress($sendto, $senn);  // Add a recipient
    //$mail->AddAddress('myemail@gmail.com');               // Name is optional
    
    $mail->IsHTML(true);                                  // Set email format to HTML

尝试执行此操作时出现错误:

致命错误:无法在第 33 行的 C:\wamp\www\hrm\Emails\smtp\PHPMailer.php 中重新声明类 PHPMailer\PHPMailer\PHPMailer

标签: phpemailphpmailer

解决方案


您在 php 脚本中两次声明 PHPMailer.php 类请删除行 require '../Emails/smtp/PHPMailer.php'; 在 SendMail 函数中 ...因为您已经在脚本的开头声明了 PHPMailer 类。

谢谢


推荐阅读