php - 使用phpmailer发送邮件的功能不断加载没有警告
问题描述
我正在测试 phpmailer 发送电子邮件,我创建了一个类来发送电子邮件,但页面一直加载,直到超时
我创建了下面的类,我在另一个文件中引用这个类,该文件应该在加载时发送电子邮件
class ManageEmails
{
private $pdo;
private $mail;
public function __construct(\PDO $pdo, PHPMailer $mail)
{
$this->pdo = $pdo;
$this->mail = $mail;
}
public function sendEmail($toEmail, $subject, $message, $file_path='')
{
$this->mail->setFrom('info@afrojp.com', 'Darth Vader');
$this->mail->addAddress($toEmail, 'Emperor');
$this->mail->Subject = $subject;
$this->mail->Body = $message;
$this->mail->isSMTP();
$this->mail->Host = 'smtp.gmail.com';
$this->mail->Port = '587';
$this->mail->SMTPAuth=true;
$this->mail->SMTPSecure='tls';
// need to get smtp username
$this->mail->username = 'myemail@gmail.com';
$this->mail->password ='appPassword';
//we can set true if we have ssl otherwise leave blank;
$this->mail->wrap = 50;
$this->mail->isHTML(true);
// if there is an attachment
if($file_path='') $this->mail->AddAttachment($file_path);
if($this->mail->send())
{
return true;
}
else return false;
}
然后我调用了发送邮件方法;
require 'classes/PHPMailer/src/Exception.php';
require 'classes/PHPMailer/src/PHPMailer.php';
require 'classes/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$manageEmails = new ManageEmails($pdo,$mail);
$manageEmails->sendEmail('msiskasmith@gmail.com','Hello Trial', 'Whoop whoop');
当我期望它发送电子邮件时,页面继续加载
解决方案
推荐阅读
- angular - 使用自定义模板渲染无限树
- wordpress - Wordpress - 在所有帖子中批量取消选中次要类别
- bash - 并行:如何从函数中引用多个参数
- github - 为什么 GitHub 显示不存在的图像?
- qt - 当对象变为无线程时,如何防止 QBasicTimer::stop: Failed 警告?
- r - R 在 mathjax 条件案例中闪闪发光
- angular - 角材料底片不会在几秒钟内将数据绑定到内部内容?
- java - 如何使用 Java 和 MySql 在 Json 中获取正确的日期格式
- java - 使用 gradle bootJar 而不是 jar 任务并在 Jenkins 中构建失败
- reactjs - React Redux Firebase 文件上传