I created a phpMailer class and call it into my register.php file all fine. But dont find a way how to send emails from class.
Here is my class:
clas
You need to define variables before you use them!
require "modules/mailer.php";
$email_send = new mailSend();
$subject = "Please verify email!";
$message = "Thanks for signing up!
Please click on the link below:
".$url."";
$email_send->sendMail($email,$message,$subject);
To get PHPMailer to throw exceptions, you need to ask it, by passing true
to the constructor:
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
Now to get responses out of your class, you need to return something, so change the end of your send function to this:
$result = [];
$mail->send();
$result['success'] = true;
$result['message'] = "Mail sent.";
} catch (Exception $e) {
$result['success'] = false;
$result['message'] = "Failed. Mailer error: {$mail->ErrorInfo}";
}
return $result;
Then when you call your function:
$result = $email_send->sendMail($email,$message,$subject);
if ($result['success']) {
echo $result['message'];
//Do whatever else you want to do on success
} else {
echo $result['message'];
}