PHP MAILER错误自动加载文件 [英] PHP MAILER error autoload file
问题描述
我对php mailer有问题. 因此,在教程中,他谈到了自动加载文件,但是当我下载phpmailer文件夹时,该文件不在其中,我是否必须创建它?
i have a problem with php mailer . So on the tutorials he talks about the autoload file but when I download the folder phpmailer this file is not in , do I have to create it ?
所以我仍然尝试在src文件夹中使用文件phpmailer.php,但这使我出错,这是错误的地方:
so I still try with the file phpmailer.php in the folder src but that puts me error , here is the mistake :
Fatal error: Class 'PHPMailer' not found in C:\wamp64\www\site ajft\contact.php on line 14
这是我的代码:
<?php
use League\OAuth2\Client\Grant\RefreshToken;
ini_set("display_errors", 1);
error_reporting(E_ALL);
$msg ="";
if(isset($_POST['submit'])) {
require 'phpmailer/src/PHPMailer.php';
function sendmail($to, $from, $fromname, $tel , $body) {
*(line 14) $mail = new PHPMailer ;
$mail->setFrom($from, $fromname);
$mail->addAddress($to);
$mail->Subject = 'Contact Form - Email';
$mail->Body = $body;
//$mail->isHTML(isHTML: false);
return $mail->send();
}
$name = $_POST['nom'];
$email = $_POST['mail'];
$tel = $_POST['objet'];
$body = $_POST['message'];
if (sendmail('Myemail@lf.com', $email, $name , $tel, $body)) {
$msg = 'email envoyé';
} else
$msg = 'email non envoyé';
}
?>
如果有人可以告诉我该如何解决此问题,请先感谢
if anyone can tell me what to do to fix this problem, thanks in advance
推荐答案
您缺少重要的内容.同时删除require 'phpmailer/src/PHPMailer.php';
you are missing important stuff. Also remove require 'phpmailer/src/PHPMailer.php';
autoload.php
由作曲家创建. PHPMailer不再拥有自己的自动加载器,因为composer可以做得更好.如果您不想使用作曲家,则可以按照自述文件中的说明手动加载文件.
autoload.php
is created by composer. PHPMailer no longer has its own autoloader because composer makes a much better job of it. If you don't want to use composer, you can load the files manually as described in the readme.
编写器方式:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
手动方式:
<?php
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脚本.
这篇关于PHP MAILER错误自动加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!