MAILER ERROR: Could not Instantiate Mail Function, Php mailer

MAILER ERROR: Could not Instantiate Mail Function, Php mailer

我正在使用 php 邮件程序将邮件程序发送到我域中的电子邮件帐户,使用从表单元素中获取的信息,但它带来了这个错误 Could not Instantiate Mail Function,我试过了在我的 xamp 服务器上和在我的域上也在线,它仍然不起作用,请问我做错了什么,下面是我的代码,是因为我没有使用 SMTP,请问我的错误在哪里

<?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_POST['button'])) {
        $solution =     mailer($_POST['first_name'],$_POST['last_name'],$_POST['phone_number'],
        $_POST['ref_phone_number'], $_POST['type_of_vehicle'], $_POST['vehicle_model'],
        $_POST['vehicle_plate_no']) . "<br/>";
        echo $solution;   
}
function mailer($first_name, $last_name, $phone_number, $ref_phone_number,     $type_of_vehicle, $vehicle_model,$vehicle_plate_no){
require_once "vendor/autoload.php";

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "earlybird@mendelsmore.com";
$mail->FromName = $first_name." ".$last_name;

//To address and name
$mail->addAddress("mendelsnzeh@mendelsmore.com"); //Recipient name is optional

//Address to which recipient will reply
$mail->addReplyTo("info@mendelsmore.com", "Reply");

//Send HTML or Plain Text email


$mail->Subject = "Early Bird Subscription for ".$first_name." ".$last_name;
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;"  cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td> <td>" . $first_name." ".$last_name . "</td></tr>";
$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . $phone_number . "</td></tr>";
$message .= "<tr><td><strong>Referral Phone Number:</strong> </td><td>" .  $ref_phone_number . "</td></tr>";
$message .= "<tr><td><strong>Type of vehicle:</strong> </td><td>" .   $type_of_vehicle . "</td></tr>";
$message .= "<tr><td><strong>Vehicle Model:</strong> </td><td>" . $vehicle_model . "</td></tr>";
$message .= "<tr><td><strong>Vehicle Plate Number:</strong> </td><td>" . $vehicle_plate_no . "</td></tr>";
$mail->Body = $message;
$mail->isHTML(true);
// $mail->AltBody = "This is the plain text version of the email content";

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

<body>
    <h2>Early Bird Subscription</h2>
    <div class="row" style="margin-left: 10px;">
        <form name="mailer" method="post">
        <div class="form-group">
 <input type="text" name="first_name" class="form-control" placeholder="First Name" required>
</div>
<div class="form-group">
<input type="text" name="last_name" class="form-control" placeholder="Last Name" required>
     </div>
 <div class="form-group">
 <input type="number" name="phone_number" class="form-control" placeholder="Phone Number" required>
 </div>
 <div class="form-group">
 <input type="number" name="ref_phone_number" class="form-control"  placeholder="Referral Phone Number" required>
  </div><div class="form-group"><input type="text" name="type_of_vehicle" class="form-control" placeholder="Type of Vehicle" required>
  </div>
  <div class="form-group">
  <input type="text" name="vehicle_model" class="form-control" placeholder="Vehicle Model" required>
  </div>
  <div class="form-group">
  <input type="text" name="vehicle_plate_no" class="form-control" placeholder="Vehicle Plate Number" required>
   </div>
   <div class="form-group">
   <button type="submit" class="btn btn-primary btn-block btn-flat"    name="button">Sign Up</button>
   </div>           </form>
    </div>
  </body>

您没有在代码中包含 PHPMailer class。

将其放在代码的顶部。

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

此方法不需要使用自动加载器。以这种方式尝试一下,看看它是否有效。然后你可以修改自动加载器。

这在文档和此处的许多重复问题中都有介绍。

您收到此错误是因为您正在使用 PHP 的内置邮件功能(这是 PHPMailer 默认使用的功能)发送,但您没有本地邮件服务器已安装或配置。安装一个邮件服务器就可以了

或者,使用 SMTP 连接到远程邮件服务器。请参阅 PHPMailer 提供的许多示例以了解如何执行此操作。