PHPMailer not working

I’m trying to send a mail from my contact form using PHPMailer. It is working fine in localhost but I have a problem here on InfinityFree
What I’m seeing is: HTTP ERROR 500
Here;s my PHP Code for sending the mail:





require ("src/PHPMailer.php");

require ("src/Exception.php");

require ("src/SMTP.php");

require ("src/OAuth.php");

require ("src/POP3.php");

$mail = new PHPMailer();


$mail->Host = '';

$mail->Port = 587;

$mail->SMTPSecure = 'tls';

$mail->SMTPAuth = true;

$mail->Username = 'myusername';

$mail->Password = 'mypassword';

$mail->SMTPDebug = 2;

$mail->setFrom('[email protected]', 'Name');

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

$mail->Subject = 'Test';

if(!$mail->send()) {

echo ‘Message was not sent.’;

echo 'Mailer error: '. $mail->ErrorInfo;

} else {

echo 'Message has been sent.';


Please help me with this. Thanks in Advance.

enable display errors first

1 Like

Thank You but now the error shown is:

Fatal error : Uncaught Error: Class ‘PHPMailer’ not found in /home/vol4_6/ Stack trace: #0 {main} thrown in /home/vol4_6/ on line 14

As I have mentioned in the code, phpmailer.php is in the location mentioned i.e in the src folder. Please help me with this.

Now it’s working
I have moved out the files from src directory to phpmailer directory and used
use PHPMailer\PHPMailer\PHPMailer;
And now it;s working fine

Thank You

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.