phpmailer停止工作Mailer错误:致命错误:未捕获的错误:未找到类'PHPMailer'

我的邮件发件人停止工作了,无法再次使用。我从githhub下载了最新的phpmailer 5.5并重新编码了页面。我使用示例创建了我的邮件程序并创建了我的表单,当我打开错误报告时,我无法弄清楚这个错误。我在您的网站上查看了示例,但确实无法使用
Fatal error: Class 'PHPMailer' not found
我的服务器使用的是带有Corna病毒的PHP版本7.3.15,这对于我保持生存至关重要。您能帮我吗?




<!DOCTYPE html>
<html lang="en" class="no-js">
<meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1">
<head>
<meta charset="utf-8">
<title>test | semndinbg mail</title>
<link rel="stylesheet" href="css/repairstatus.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
</head>
<body>



<form id="form_1130906" class="appnitro"  method="post" action="">

<div id="contact_slide1">							
				
<div id="contact_name">FULL NAME: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/></div> 
		
        
<div id="contact_phone">PHONE NUMber: *<br>
<input id="element_2_1" name="phone" class="element text" size="15" maxlength="15" value="" type="text" placeholder="PHONE NUMber"></div> 	
			
</div> <!--contact_slide1-->
<div id="contact_slide2">

<div id="contact_email">VEHICLE MAKE: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: FORD"/></div> 

<div id="contact_contact">VEHICLE MODEL: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: TAURUS"/></div> 



</div> <!--contact_slide2-->


<div id="contact_message">MESSAGE:<br>
<textarea id="element_3" name="message" class="element textarea medium" placeholder="START TYPING MESAGE HERE..."></textarea></div> 

			    
                
                
<div id="contact_slide3">              
<input id="saveForm" class="button_text" type="submit" name="submit" value="SEND" />
</div><!--contact_slide3-->       
               


		</form>	





<?php




if (isset($_POST['submit'])){



//check if post form was submitted
if(isset($_POST)){
//check if hidden value was used
if(isset($_POST['miles']) && trim($_POST['miles']) !=''){
die('THERE WAS AN ERROR');
}
//implode all the post data and check against bad words in a text file
$my_bad_file = "inc/words.txt"; //make a new file and insert any bad items one per line,Phrases work as well
if(!file_exists($my_bad_file)){
die("Can't find $my_bad_file");
}
$check_content = implode(",",$_POST);
$bad_content_array = array_map('rtrim',file($my_bad_file));
foreach ($bad_content_array as $bad_content) {
$bad_content = strtolower($bad_content);
if (strpos(strtolower($check_content),$bad_content) !== false) {
die('THERE WAS A BAD ERROR');
}}

}

    echo "Mailer Error:" . $mail->ErrorInfo;
    ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);









 require("inc/PHPMailer2/src/PHPMailer.php");
  require("inc/PHPMailer2/src/SMTP.php");

    $mail = new PHPMailer/PHPMailer/PHPMailer();
    $mail->IsSMTP(); // enable SMTP









//Create a new PHPMailer instance

$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;

//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 mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

//Whether to use SMTP authentication
$mail->SMTPAuth = true;


//username to use for SMTP authentication - use full email address for gmail
$mail->username = 'test@gmail.com';

//Password to use for SMTP authentication
$mail->Password = 'aaaa1111';

//Set who the message is to be sent from
$mail->setfrom('from@example.com','First Last');

//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com','First Last');

//Set who the message is to be sent to
$mail->addAddress('whoto@example.com','John Doe');

//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'),__DIR__);

//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');

$mail->AddAddress('test@test.com');




$mail->Priority = 1;
$mail->WordWrap = 50;   // set word wrap
$mail->IsHTML(true);   // send as HTML
$mail->Subject  =  "FINE LINE AUTO BODY | Repair Status";	
$mail->AltBody  =  "This is the text-only body";

$name = isset($_POST['name']) ? $_POST['name'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$make = isset($_POST['make']) ? $_POST['make'] : '';
$model = isset($_POST['model']) ? $_POST['model'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';

// gets info from form
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$make = $_POST['make'] ;
$model = $_POST['model'] ;

$message = $_POST['message'] ;





$ip = $_SERVER["REMOTE_HOST"] ?: gethostbyaddr($_SERVER["REMOTE_ADDR"]);


 // defines how message looks in email
$mail->Body="
<html>
<head>
</head>
<body>
<center>

<span style='color:red;'>This is from a customer,We are repairing his vehicle. Lets not keep them waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'>Full Name: $name<br></span>
<br>
<span style='font-size:px;'>Phone Number: $phone<br></span>
<br>
<span style='font-size:px;'>Vehicle Make: $make<br></span>
<br>
<span style='font-size:px;'>Vehicle Model: $model<br></span>
<br>
<span style='font-size:px;'>Message: $message<br></span>

</div></div>
</center>
</body>
</html> 


";




// looks good in your inbox





//send the message,check for errors
if (!$mail->send()) {
    echo "Mailer Error:" . $mail->ErrorInfo;
} else {
    echo '<meta http-equiv="refresh" content="0;url=https://www.sucess.com/">';
}}



?>





</body>
</html>

zt48475144 回答:phpmailer停止工作Mailer错误:致命错误:未捕获的错误:未找到类'PHPMailer'

您做了两次相同的事情,但是第二次却是错误的(不必要的)。

这种创建实例的方法对于PHPMailer 6.0及更高版本是正确的(尽管您可以使用别名使它看起来更好)。注意斜线的方向:

$mail = new PHPMailer\PHPMailer\PHPMailer();

这跟说的一样:

use PHPMailer\PHPMailer\PHPMailer;
...
$mail = new PHPMailer();

稍后在代码中,您正在执行此操作(没有更早的use语句):

$mail = new PHPMailer;

除非您声明PHPMailer命名空间或将命名空间的类名称导入到您自己的命名空间,否则它将无法工作。无论如何-这是重复的,您只需删除此行即可。

您可能想阅读the upgrade guide provided with PHPMailer

本文链接:https://www.f2er.com/2595920.html

大家都在问