0

I am trying to send mail using phpmailer from joomla model, here is code

require '/opt/cdf/ThemeComponent/models/vendor/autoload.php';
            require("/opt/cdf/ThemeComponent/models/PHPMailer-master/src/Exception.php");
            require("/opt/cdf/ThemeComponent/models/PHPMailer-master/src/PHPMailer.php");
            require("/opt/cdf/ThemeComponent/models/PHPMailer-master/src/SMTP.php");

            use PHPMailer\PHPMailer\PHPMailer;
            use PHPMailer\PHPMailer\Exception;

            $email = new PHPMailer();
            $email->IsSMTP();
            $email->SMTPSecure = false;
            $email->SMTPAutoTLS = false;
            $email->Host = "stage1.dmz.gr";
            $email->Mailer = "smtp";
            $email->Port = 25;
            $email->CharSet = 'UTF-8';
            $email->Encoding = 'base64';
            $email->IsHTML(true);
            $email->SetFrom("noreply@mydomain.com");
            $email->Subject = "ok";
            $email->Body = "<b>asdf</b>";
            $email->AddAddress("wasimxe@gmail.com");
            $email->Send();

This code is working fine out of joomla directory but when I use it in joomla model, it throw http error no. 500 and if i commend line use PHPMailer\PHPMailer\PHPMailer; then error gone but mail doesn't sent.

Wasim A.
  • 9,660
  • 22
  • 90
  • 120

1 Answers1

0

The use statement is for importing namespaced classes into your current namespace, and you can read the docs on it. It was introduced in PHP 5.3, so this error suggests you are running PHP 5.2 or older, which is a very, very bad idea as it has not received security patches for over 8 years. Your server is vulnerable to many known attacks, so you should upgrade immediately.

Synchro
  • 35,538
  • 15
  • 81
  • 104