PHPMailer根本不工作

PHPMailer根本不工作,php,phpmailer,Php,Phpmailer,我正在尝试配置PHPMailer我上传了一个文件class.PHPMailer.php,并创建了另一个包含以下内容的php文件: <?php require('class.phpmailer.php'); $mail = new PHPMailer(); // create a new object $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; // debugging: 1 = errors and message

我正在尝试配置PHPMailer我上传了一个文件class.PHPMailer.php,并创建了另一个包含以下内容的php文件:

<?php
require('class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("the same email address");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("the same email address");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>


我什么也得不到,既没有成功的信息,也没有失败的信息

问题在于require方法

首先必须提取phpMailer存储库的所有文件

而不是写作

require('class.phpmailer.php');
您需要包括phpmailerautoad.php文件提取的路径。这样您就可以将其替换为

require('path-of-extracted-folder/PHPMailerAutoload.php');
有关更多参考信息,请访问它的GitHub链接


我也遇到了同样的问题,但我解决了。这是我编写代码的方式

<?php 


require 'PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';              // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'abc@gmail.com';                 // SMTP username
$mail->Password = 'abc';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

//Set who the message is to be sent from
$mail->setFrom('abc1@gmail.com', 'First Last');
//Set an alternative reply-to address

//Set who the message is to be sent to
$mail->addAddress('abc@gmail.com', 'Shehan');
//Set the subject line
$mail->Subject = 'Test Mail';

$mail->Body = 'This is Test Mail';


//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
} 

?>

现在所有答案都过时了。最新版本(截至2018年2月)不再自动加载,PHP编译器应按如下方式初始化:

<?php

  include_once(FCPATH.'PHPMailer/src/PHPMailer.php');
  include_once(FCPATH.'PHPMailer/src/SMTP.php');
  include_once(FCPATH.'PHPMailer/src/Exception.php');

    $msj="My complete message";
    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    //authentication SMTP enabled
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    //indico el puerto que usa Gmail 465 or 587
    $mail->Port = 465; 
    $mail->Username = "xxxxxx";
    $mail->Password = "xxxx";
    $mail->SetFrom("xxxxxx@xxxxx.com","Name");
    $mail->AddReplyTo("xxx@xxx.com","Name Replay");
    $mail->Subject = "Test";
    $mail->MsgHTML($msj);
    $mail->AddAddress("xxxxxx@xxxxx.com");

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }
?>


检查日志。如果日志为空,请检查php.ini中是否启用了日志记录。将此添加到文件开头以显示所有错误消息:
error\u reporting(E\u all);ini_集('display_errors','1')警告:require(phpmailerautoad.php):未能打开流:第575行的/home/iy0xods5/public_html/mailtest/class.phpmailer.php中没有此类文件或目录警告:require(phpmailerautoad.php):未能打开流:第575行的/home/iy0xods5/public_html/mailtest/class.phpmailer.php中没有此类文件或目录致命错误:require():无法打开所需的“phpmailerautoad.php”(include_path=”。:/usr/lib/php:/usr/local/lib/php)在第575行的/home/iy0xods5/public_html/mailtest/class.phpmailer.php中,但文件已经存在,同名phpmailer需要其他文件。
class.phpmailer.php
不包含所有代码。请检查phpmailer的安装手册。此文件已经上载,我现在已上载此文件phpmailerautoad.php和现在我得到了这个错误:致命错误:在线/home/iy0xods5/public_html/mailtest/Class.phpmailer.php中找不到类“SMTP”1147@Juliana_Torres很好的回答