-2

Fatal error: Class 'PHPMailer' not found

That is the error that comes up but I have tried everything.

                            $mail = new PHPMailer;
                            $mail->IsSMTP(); // Enable SMTP 
                            $mail->Host = "secret"; //SMTP server Take 163 mailbox as an example 
                            $mail->Port = 465; //email-sending-port 
                            $mail->SMTPAuth = true; //Enable SMTP authentication
                            $mail->SMTPSecure = 'ssl';

                            $mail->CharSet = 'UTF-8'; //character set 
                            $mail->Encoding = "base64"; //encoding style 

                            $mail->Username = "secret"; //your email 
                            $mail->Password = "secret"; //your password 
                            $mail->Subject = "secret"; //Mail Subject 

                            $mail->From = "secret"; //Sender address (aka your email) 
                            $mail->FromName = "secret"; //Sender Name
                            $mail->setFrom('secret', 'secret');

                            $address = $_POST['email'];//recipient email 
                            $mail->AddAddress($address, $_POST['username']);//Add recipient (address, nickname) 


                            $mail->IsHTML(true); //support html content 

                            $mail->Body = "<p>secret</p> ";

.. And this is right at the top:

require 'inc/pages/vendor/autoload.php';


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;```

1 Answers1

0

By default PHPMailer Class name is available, no need to import that class in same name.

Try this,

use PHPMailer\PHPMailer\PHPMailer;

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient1@example.com"); //Recipient name is optional

//Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply");

//CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

Note: composer package composer require phpmailer/phpmailer

jithu thomas
  • 279
  • 1
  • 3
  • What about the host port and whatnot should I add this in – Drakey SAMP May 09 '20 at 05:45
  • If enable SMTP, Then you have to set host, port, and auth, etc – jithu thomas May 09 '20 at 05:49
  • Have tried this with the same error result; Fatal error: Class 'PHPMailer' not found. – Drakey SAMP May 09 '20 at 06:17
  • Update: I've done $mail = new PHPMailer\PHPMailer\PHPMailer(); and this has resulted in a new error ? Mailbox Error: Could not instantiate mail function. – Drakey SAMP May 09 '20 at 06:20
  • Are you try to using SMTP? then as I mentioned earlier please set the following config. $mail->IsSMTP(); $mail->Host = "smtp.example.com"; // optional // used only when SMTP requires authentication $mail->SMTPAuth = true; $mail->Username = 'smtp_username'; $mail->Password = 'smtp_password'; – jithu thomas May 09 '20 at 06:34
  • Yes, I am trying to use SMTP. This error is now showing up after following your instructions: Mailbox Error: SMTP connect() failed. – Drakey SAMP May 09 '20 at 06:39
  • this is mostly because of the firewall rules on their infrastructure which explicitly blocks the outgoing SMTP connection to ports 25, 587 and 465 to all external servers. – jithu thomas May 09 '20 at 08:03