我正在测试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;
}
然后我调用了send mail方法;
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');
我希望页面发送电子邮件时页面一直处于加载状态