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:
class mailSend {
public function sendMail($email, $message, $subject)
{
require_once('PHPMailer/src/Exception.php');
require_once('PHPMailer/src/PHPMailer.php');
require_once('PHPMailer/src/SMTP.php');
$mail = new PHPMailerPHPMailerPHPMailer();
try {
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->Port = 587;
$mail->setFrom('admin@example.com', 'Mailer');
$mail->addAddress($email);
$mail->addReplyTo("user@gmail.com", "Alias");
$mail->CharSet = "UTF-8";
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
$success['success'] = "Mail sent.";
} catch (Exception $e) {
$errors['mail'] = "Failed. Mailer error: {$mail->ErrorInfo}";
}
}
}
This is the usaqe:
require "modules/mailer.php";
$email_send = new mailSend();
$email_send->sendMail($email,$message,$subject);
And Here is my problem part, I am trying to send a confirmation link to user on registration and dont know how to do it, I tried several methods but couldnt make it work:
Here is how I am trying to send and having error :
Notice: Undefined variable: message in
D:Wampwwwhtmlmodules
egister.php on line 115
require "modules/mailer.php";
$email_send = new mailSend();
$email_send->sendMail($email,$message,$subject);
$subject = "Please verify email!";
$message = "Thanks for signing up!<br>
Please click on the link below:<br><br>
<a href=".$url.">".$url."</a>";
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…