PHP致命错误:require():无法打开所需的“vendor/phpmailer/phpmailer/src/Exception.PHP”
下面是我的php代码。我第一次使用gcp应用程序引擎,它抛出错误PHP致命错误:require:无法打开必需的“vendor/phpmailer/phpmailer/src/Exception.PHP”。我已经在提到的目录中有了这个文件,然后它也显示了这个错误。是关于新的phpmailer格式还是其他什么?请帮忙PHP致命错误:require():无法打开所需的“vendor/phpmailer/phpmailer/src/Exception.PHP”,php,Php,下面是我的php代码。我第一次使用gcp应用程序引擎,它抛出错误PHP致命错误:require:无法打开必需的“vendor/phpmailer/phpmailer/src/Exception.PHP”。我已经在提到的目录中有了这个文件,然后它也显示了这个错误。是关于新的phpmailer格式还是其他什么?请帮忙 <!DOCTYPE html> <html lang="en"> <head> <meta content="text/html;c
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
// Include autoload.php file
require 'vendor/autoload.php';
// Create object of PHPMailer class
$mail = new PHPMailer(true);
$output = '';
if (isset($_POST['submit'])) {
$name = $_POST['contactName'];
$email = $_POST['contactEmail'];
$subject = $_POST['contactSubject'];
$message = $_POST['contactMessage'];
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
// Gmail ID which you want to use as SMTP server
$mail->Username = 'rajeshsingh80906@gmail.com';
// Gmail Password
$mail->Password = 'secret';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Email ID from which you want to send the email
$mail->setFrom('rajeshsingh80906@gmail.com');
// Recipient Email ID where you want to receive emails
$mail->addAddress('ranarajesh495@gmail.com');
// $mail->addAttachment('');
$mail->isHTML(true);
$mail->Subject = 'Form Submission';
$mail->Body = "<h3>Name : $name <br>Email : $email <br>Message : $message</h3>";
$mail->send();
$output = '<div class="alert alert-success">
<h5>Thankyou! for contacting us, We\'ll get back to you soon!</h5>
</div>';
} catch (Exception $e) {
$output = '<div class="alert alert-danger">
<h5>' . $e->getMessage() . '</h5>
</div>';
}
}
?>
<title>insert page</title>
<script type="text/javascript">
function back_to_main() {
setTimeout(function () {
//Redirect with JavaScript
window.location = './index.html'
}, 5000);
}
</script>
<body onload='back_to_main();'>
thank you...
</body>
</html>
在搜索StackOverflow上已经存在的案例时,我发现了这个: 另外,如果我没有错,您需要在使用use语句之前导入文件,如下所示:
<?php
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
如果您通过composer安装了PHPMailer,我认为您不需要这个,所以我已经从您的代码中删除了这个部分 需要“vendor/phpmailer/phpmailer/src/Exception.php”; 需要“vendor/phpmailer/phpmailer/src/phpmailer.php”; 需要“vendor/phpmailer/phpmailer/src/SMTP.php”; 请尝试下面的代码。我已经重新格式化了你的代码 插入页面 功能返回至主{ setTimeoutfunction{ //使用JavaScript重定向 window.location='./index.html' }, 5000; } 非常感谢。 请注意,我没有测试上述代码
有关更多信息,请阅读您是否未使用composer?为什么要单独包含phpmailer文件?另外,“需要”应该放在“使用”之前。我厌倦了上面的事情,它也不起作用。它现在抛出以下错误-未声明HTML文档的字符编码。如果文档包含US-ASCII范围之外的字符,则在某些浏览器配置中,文档将呈现乱码文本。页面的字符编码必须在文档或传输协议中声明。@ra459我给你的代码没有问题!这是PHPMailer正在抛出的异常。您只需要正确配置PHPMailer设置。我已经修复了您原来的问题。我已经解决了上述不相关的问题,但是在应用了您所说的更改之后,现在我得到了这个错误。require:打开所需的“vendor/autoload.php”include_path=”失败/base/data/home/apps/j~dt-website-278313/20200612t145411.427336870951406362//base/alloc/tmpfs/dynamic_runtimes/php55g/6485fc5dd706e6f8/sdk“您有什么原因不能要求使用由Composer自动生成的autoload.php文件吗?我猜您没有通过Composer正确安装PHPMailer,或者autoload.php文件的路径不正确。我已经解决了这个问题。实际上gcp没有标识autolaod.php,所以我不得不使用gcpmailer。