致命错误:未捕获错误:类';PHPMailer\PHPMailer\SMTP';在D:\projects\cscpl\PHPMailer.php中找不到
我在没有composer的情况下手动安装了PHPMailer,并在cscpl文件夹中添加了五个文件。我在用gmail发邮件。但我有以下错误致命错误:未捕获错误:类';PHPMailer\PHPMailer\SMTP';在D:\projects\cscpl\PHPMailer.php中找不到,php,email,phpmailer,Php,Email,Phpmailer,我在没有composer的情况下手动安装了PHPMailer,并在cscpl文件夹中添加了五个文件。我在用gmail发邮件。但我有以下错误 Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\SMTP' not found in D:\projects\cscpl\PHPMailer.php:1824 Stack trace: #0 D:\projects\cscpl\PHPMailer.php(1945): PHPMailer\P
Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\SMTP' not found in
D:\projects\cscpl\PHPMailer.php:1824 Stack trace: #0 D:\projects\cscpl\PHPMailer.php(1945):
PHPMailer\PHPMailer\PHPMailer->getSMTPInstance() #1 D:\projects\cscpl\PHPMailer.php(1861):
PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #2 D:\projects\cscpl\PHPMailer.php(1604):
PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Thu, 17 S...', 'This is a multi...') #3
D:\projects\cscpl\PHPMailer.php(1436): PHPMailer\PHPMailer\PHPMailer->postSend() #4
D:\softwares\installed\xampp\htdocs\contact.php(91): PHPMailer\PHPMailer\PHPMailer->send()
#5 {main} thrown in D:\projects\cscpl\PHPMailer.php on line 1820
在cscpl文件夹中,我有一个contact.php文件,其中包含以下内容
<?php
require_once('config.php');
use PHPMailer\PHPMailer\PHPMailer;
// use PHPMailer\PHPMailer\Exception;
// require_once('D:\projects\cscpl\Exception.php');
require_once('D:\projects\cscpl\PHPMailer.php');
require_once('D:\projects\cscpl\SMTP.php');
$subject = "This is subject";
$msg = "This is message";
try{
echo 'trying';
$php_mailer = new PHPMailer(true);
$php_mailer->isSMTP();
$php_mailer->Host = 'smtp.gmail.com';
$php_mailer->SMTPAuth = true;
$php_mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$php_mailer->Port = 587;
$php_mailer->Username = 'sender_email@gmail.com';
$php_mailer->Password = 'sender_pwd';
$php_mailer->setFrom('sender_email@gmail.com');
$php_mailer->addAddress('receiver_email@gmail.com');
$php_mailer->IsHTML(true);
$php_mailer->Subject = $subject;
$php_mailer->Body = 'HTML message body. <b>Gmail</b>'.$msg.' .';
$php_mailer->send();
echo 'done';
}
catch (Exception $e)
{
echo 'exp';
/* PHPMailer exception. */
echo $e->errorMessage();
print_r(error_get_last());
}
smtp.php文件如下所示
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
}
}
您显示的文件内容是SMTP.php
实际上是Exception.php
中的内容
这就是为什么您的只需要_一次('D:\projects\cscpl\SMTP.php')代码>不会失败,但随后创建SMTP类实例的尝试会失败
用正确的名称重新安装文件
你真的不应该去碰图书馆的文件;composer会为您处理好所有这些。为什么没有composer您就这么做了?听起来您缺少了一个包,编写器可能包含了在D:\projects\cscpl\PHPMailer.php:1824中找不到的,这意味着其中有一个对应用程序无法看到的类的引用。您应该转到这一行,查看发生了什么并进行跟踪。检查SMTP.php
是否实际包含预期的类定义require_once
是一个应用程序不太确定自己的依赖关系管理工作方式的标志。当您选择不使用composer时,它会产生大量额外的问题;花时间去做是非常值得的。@PratikSharma-这不应该是一个障碍,你可以在本地环境中安装一个composer,然后将项目连同软件包一起推到你的主机上-你不需要在主机帐户上运行composer OK,我想我最好用composer安装。是的,你绝对是个作家。我在Exception.php和smtp.php文件中都有相同的内容。这是我的错。。非常感谢,现在邮件正在发送。@PratikSharma您能选择这个答案作为正确答案吗?谢谢
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5.
*
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output.
*
* @return string
*/
public function errorMessage()
{
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
}
}