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:

<?php

date_default_timezone_set('Etc/UTC');

ini_set('display_errors','On');

error_reporting(E_ALL);

require ("src/PHPMailer.php");

require ("src/Exception.php");

require ("src/SMTP.php");

require ("src/OAuth.php");

require ("src/POP3.php");

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->Host = 'smtp.gmail.com';

$mail->Port = 587;

$mail->SMTPSecure = 'tls';

$mail->SMTPAuth = true;

$mail->Username = 'myusername';

$mail->Password = 'mypassword';

$mail->SMTPDebug = 2;

$mail->setFrom('frommail@example.com', 'Name');

$mail->addAddress('recipient@example.com', '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/epizy.com/epiz_25414140/htdocs/send_form_email.php:14 Stack trace: #0 {main} thrown in /home/vol4_6/epizy.com/epiz_25414140/htdocs/send_form_email.php 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.