首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPMailer似乎未正确安装:未捕获错误: Class 'PHPMailer\PHPMailer\PHPMailer

PHPMailer似乎未正确安装:未捕获错误: Class 'PHPMailer\PHPMailer\PHPMailer
EN

Stack Overflow用户
提问于 2019-01-05 01:05:09
回答 3查看 157关注 0票数 1

当我运行我的代码时,我得到了上面的错误。按照PHPMAiler Github页面上的说明,我在composer.json中添加了" PHPMailer /phpmailer":"^6.0“,但PHPMailer似乎没有加载。

我尝试使用$mail = new PHPMailer\PHPMailer\PHPMailer(true)代替$Mail = new PHPMailer(true)。我去了Composer IRC频道看看我的问题是不是与Composer有关。我也尝试过在require 'vendor/autoload.php';语句中使用完整路径。

代码语言:javascript
复制
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';


//other code...

//Create a new PHPMailer instance
    $mail = new PHPMailer(true);

我希望PHPMailer能运行。我哪里错了?

EN

回答 3

Stack Overflow用户

发布于 2019-10-10 06:10:16

当我在本地的XAMPP服务器和composer上运行PHPMailer遇到困难时,我最终只能通过将文件加载到我的目录中来手动安装它

htdocs -index.php -Other_Program_to_run_with_PHPMailer.php -folder(PHPMailer)

代码语言:javascript
复制
    <?php

    $messege=""

    require 'PHPMailer/PHPMailerAutoload.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3;                               // Enable verbose debug output

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'insert Username';                 // SMTP username
    $mail->Password = 'insert Password';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    $mail->setFrom('insert username', 'Information');
    $mail->addAddress('who it is being sent to', 'PHP Management');     // Add a recipient
    $mail->addReplyTo('who they can reply to', 'PHP Management');

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = ;
    $mail->Body    = $message;

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'The following Message has been sent';

        echo $message;
    }

?>

从那里,我已经复制和粘贴到我的服务器上,它工作得很好。

票数 0
EN

Stack Overflow用户

发布于 2020-02-19 17:48:37

Scott

如果你阅读了这些文档,你的问题可能就解决了。首先使用下面的代码。

代码语言:javascript
复制
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
票数 0
EN

Stack Overflow用户

发布于 2021-10-07 20:52:32

只需从GIT repo链接下载phpMailer类

代码语言:javascript
复制
https://github.com/PHPMailer/PHPMailer

并提取/复制三个文件PHPMailer.php、Extension.php和SMTP.php文件将它们放在一个文件夹名称中:(PHPMailer),如下图所示:- https://i.stack.imgur.com/T6DXW.png

只需在文件的顶部添加以下几行代码

代码语言:javascript
复制
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
//  require 'vendor/autoload.php';
require('PHPMailer/Exception.php');
require('PHPMailer/SMTP.php');
require('PHPMailer/PHPMailer.php');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54043242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档