Reputation: 71
So i was just typing the following normal code for sending mail through PHPMailer:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'email';
$mail->Password = 'password';
$mail->SMTPsecure = 'tls';
$mail->Port = 587;
$mail->setFrom('email','password');
$mail->addReplyTo('email','npassword');
$mail->addAddress('email');
$mail->isHTML(true);
$mail->Subject = 'This is a test email sent with help of PHP Code..//';
$bodyContent = '<h1>Sending Email Through PHP..//</h1>';
$mail->Body = $bodyContent;
if(!$mail->send()){
echo "Message Not Sent Due to the following Error:".$mail->ErrorInfo();
}
else
{
echo "Message Sent Successfully..//";
}
?>
And the Following Error:
Warning: require(PHPMailer/Exception.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\TYBSC\Tri 8\practice\MailPractice\mailer.php on line 6
Fatal error: Uncaught Error: Failed opening required 'PHPMailer/Exception.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\TYBSC\Tri 8\practice\MailPractice\mailer.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\TYBSC\Tri 8\practice\MailPractice\mailer.php on line 6
What to do?? And yes I have included PHPMailer folder in the htdocs folder so i dont there should be any problem.
Upvotes: 0
Views: 1097
Reputation: 31
If you're not using composer, you can load the classes manually. Check the file path before you add. try this
require(__DIR__."/PHPMailer/src/PHPMailer.php");
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
.....
Upvotes: 1
Reputation: 26
your path is not correct try to use this
require './PHPMailer/Exception.php';
require './PHPMailer/PHPMailer.php'; require './PHPMailer/SMTP.php';
Upvotes: 1