亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 致命錯誤:require(): 需要打開失敗 'vendor/phpmailer/

PHP 致命錯誤:require(): 需要打開失敗 'vendor/phpmailer/

PHP
蝴蝶不菲 2023-05-26 14:19:24
下面是我的 php 代碼。我是第一次使用 gcp 應用程序引擎,它拋出錯誤 PHP Fatal error: require(): Failed opening required 'vendor/phpmailer/phpmailer/src/Exception.php'。我已經在提到的目錄中有這個文件,然后它也顯示這個錯誤。是關于新的 phpmailer 格式還是其他什么?請幫忙。<!DOCTYPE html><html>  <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 = '[email protected]';      // 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('[email protected]');      // Recipient Email ID where you want to receive emails      $mail->addAddress('[email protected]');      // $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>';    }  }
查看完整描述

3 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

如果我是正確的,您需要在使用“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;


查看完整回答
反對 回復 2023-05-26
?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

如果您通過 composer 安裝 PHPMailer,我認為您不需要這個,所以我已從您的代碼中刪除了這部分。


require 'vendor/phpmailer/phpmailer/src/Exception.php';

require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';

require 'vendor/phpmailer/phpmailer/src/SMTP.php';

試試下面的代碼。我已經重新格式化了你的代碼。


<?php

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

use PHPMailer\PHPMailer\SMTP;


// Include Composer 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 = '[email protected]';

? ? ? ? // 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('[email protected]');

? ? ? ? // Recipient Email ID where you want to receive emails

? ? ? ? $mail->addAddress('[email protected]');

? ? ? ? // $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>';

? ? }

}

?>

<!DOCTYPE html>

<html>

<head>

? ? <meta content="text/html;charset=utf-8" http-equiv="Content-Type">

? ? <title>insert page</title>

? ? <script type="text/javascript">

? ? ? ? function back_to_main() {

? ? ? ? ? ? setTimeout(function () {

? ? ? ? ? ? ? ? //Redirect with JavaScript

? ? ? ? ? ? ? ? window.location = './index.html'

? ? ? ? ? ? }, 5000);

? ? ? ? }

? ? </script>

</head>

<body onload='back_to_main();'>

? thank you...

</body>

</html>

請注意我沒有測試上面的代碼。

查看完整回答
反對 回復 2023-05-26
?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

如果您使用的是 linux 并且在沒有作曲家的情況下下載它,請授予 PHPMailer 文件夾的權限。

sudo chmod -R 777 youphpmailerfolder

在我的例子中,我將文件夾作為 PHPMailer 放在我的根項目中名為 config 的文件夾中。所以,我所做的是從項目中輸入我的文件夾配置并運行:

sudo chmod -R 777 PHPMailer

我希望這有幫助!


查看完整回答
反對 回復 2023-05-26
  • 3 回答
  • 0 關注
  • 547 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號