1 回答
TA贡献1886条经验 获得超2个赞
您需要在使用它们之前定义变量!
require "modules/mailer.php";
$email_send = new mailSend();
$subject = "Please verify email!";
$message = "Thanks for signing up!<br>
Please click on the link below:<br><br>
<a href=".$url.">".$url."</a>";
$email_send->sendMail($email,$message,$subject);
要让 PHPMailer 抛出异常,您需要通过传递true给构造函数来询问它:
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
现在要从你的类中得到响应,你需要返回一些东西,所以把你的 send 函数的结尾改成这样:
$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;
然后当你调用你的函数时:
$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'];
}
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报