php - 出现致命错误:无法重新声明类 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
解决方案
您在 php 脚本中两次声明 PHPMailer.php 类请删除行 require '../Emails/smtp/PHPMailer.php'; 在 SendMail 函数中 ...因为您已经在脚本的开头声明了 PHPMailer 类。
谢谢
推荐阅读
- c# - System.Data.Services.Client.DataServiceContext 超时属性不起作用
- javascript - 导航栏对底层背景透明
- python - 附加多个 pyplot.subplots - 如何?
- java - 一旦布尔值为真,如何关闭 JFrame?
- c# - 需要从装饰器设计模式中的组件派生装饰器
- spring-boot - 如何增加reactor WebClient的工作线程?
- qt - 在 ListView 中,如何将 currentIndex 或 currentItem 设置为动态创建的元素?
- node.js - 如何在 gitlab-runner 中启动服务器?
- asp.net - 为什么我们需要 ASP.NET 模拟:在 IIS 6.0 上为默认网站启用?
- wordpress - 如何通过编码在 WordPress 中创建照片库?