我手动安装PHPMailer没有 composer ,并在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\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());
}
在PHPMailer.php的第1824行中,它显示
public function getSMTPInstance()
{
if (!is_object($this->smtp)) {
$this->smtp = new SMTP();
}
return $this->smtp;
}
而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";
}
}
我不知道我做错了什么。
1条答案
按热度按时间xpszyzbs1#
您显示的文件的内容应该是
SMTP.php
,但实际上是Exception.php
中的内容!这就是为什么
require_once('D:\projects\cscpl\SMTP.php');
不会失败,但随后创建SMTP类示例的尝试会失败的原因。用正确的名称重新安装文件!
你真的不应该碰库文件; composer 会为你处理这一切。