问题
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 ?
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
here is my code:
<?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
回答1:
you are missing important stuff. Also remove require 'phpmailer/src/PHPMailer.php';
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.
Composer way:
<?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';
Manual Way:
<?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';
Consider using their suggested php script.
来源:https://stackoverflow.com/questions/48241899/php-mailer-error-autoload-file