我目前正在尝试设置一个简单的PMP邮件程序脚本,但我遇到了一个错误"未定义的类型"PHPMailer\PHPMailer\PHMailer"。intelphense(1009(";在代码的第14行。所以代码还不能运行。
我昨晚开始使用PMPMailer,但并不确定如何解决这个问题。问题可能是我的PHPMailer在另一个驱动器中吗?为了澄清,我正试图在Visual Studio代码中使用此代码。
<?php
use PHPMailerPHPMailerPHPMailer;
if(isset($_POST['name']) && isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer(true);
//smtp settings
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "youremail@gmail.com";
$mail->Password = 'yourpassword';
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
//email settings
$mail->isHTML(true);
$mail->setFrom($email, $name);
$mail->addAddress("youremail@gmail.com");
$mail->Subject = ("$email ($subject)");
$mail->Body = $body;
if($mail->send()){
$status = "success";
$response = "Email is sent!";
}
else
{
$status = "failed";
$response = "Something is wrong: <br>" . $mail->ErrorInfo;
}
exit(json_encode(array("status" => $status, "response" => $response)));
}
我发现的问题是Intelphense只是给了我一个错误。