Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
致命错误:类';PHPMailer&x27;在中找不到_Php_Email_Phpmailer_Require - Fatal编程技术网

致命错误:类';PHPMailer&x27;在中找不到

致命错误:类';PHPMailer&x27;在中找不到,php,email,phpmailer,require,Php,Email,Phpmailer,Require,这是第13行: Fatal error: Class 'PHPMailer' not found in C:\wamp\www\sendemail.php on line 13 我已经研究过了,他们说你需要这些: $mail = new PHPMailer(); 但是我已经有了它们,它们和sendmail.php位于同一个文件夹中,但仍然存在相同的错误 require_once('class.pop3.php'); require_once('class.phpmailer.php'); r

这是第13行:

Fatal error: Class 'PHPMailer' not found in C:\wamp\www\sendemail.php on line 13
我已经研究过了,他们说你需要这些:

$mail = new PHPMailer();
但是我已经有了它们,它们和sendmail.php位于同一个文件夹中,但仍然存在相同的错误

require_once('class.pop3.php');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
require_once('PHPMailerAutoload.php');

添加所有那些额外的
要求
行不会有帮助;只需加载自动加载器,如原始示例代码所示。尝试从绝对路径加载它:

<?php
/**
 * This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require_once('class.pop3.php');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
require_once('PHPMailerAutoload.php');
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "email@email.com";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom('email@email.com', 'name');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('email@sample.com', 'name');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
如果这样做有效,您需要检查php.ini中的设置是否包含正在加载的目录,例如,它包含
作为路径之一

我确信这是一个环境/配置问题,而不是代码问题,所以请尝试一个完全精简的脚本,如下所示:

require '/full/path/to/PHPMailerAutoload.php';

我遇到了同样的问题,并通过在用于发送邮件的PHP脚本的最顶端输入以下两行来解决它,而不仅仅是在我需要的文件中

<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;


让我知道它是否也适用于您。

您的sendmail.php中是否有名称空间?对不起,您的意思是什么?您是否在sendmail.php中添加了必需的lib文件?我编辑了我的问题,添加了sendmail.php,这是一个可能的重复:我正在使用WAMP,它已经知道我在“www”文件夹中,所以它仍然可以看到“phpmailerautood.php”,但我仍然尝试了“www/phpmailerautood.php”,但它显示了以下致命错误:require():打开所需的“www/phpmailerautood.php”(include_path=”;C:\php\pear)失败我的windows包含路径是这样的;windows:“\path1\路径2“include_path=”。;c:\php\includes“不要假设,检查。尝试绝对路径。致命错误:在第13行的c:\wamp\www\sendmail.php中找不到类'PHPMailer'。请注意,
和调用文件的位置不一定相同-
\uu DIR\uu.'/file.php'
/file.php
可能是不同的路径。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
?>