我正在尝试为我们的图书馆创建一个邮件系统。人们在索取书籍时会收到一封电子邮件。不过,我希望他们也能在提交日期前一天收到一封电子邮件。
所以我不是在寻找 sleep 脚本代码,而是在寻找可以将数据存储在服务器上直到提交日期到来的代码。
我的网站使用的是 Joomla 3.5.1,这是 PHPMailer 的代码:
jimport('joomla.mail.mail');
try{
$mail = new PHPMailer();
$body = $mailmsgadmin;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "example.host.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "example.host.com"; // sets the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "email"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->SetFrom('email', 'First Last');
$mail->AddReplyTo($mailuseremail, $mailusername);
$mail->Subject = $mailsubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("Users e-mail","Users name");
if(!$mail->Send()) {
JError::raiseWarning( 'SOME_ERROR_CODE', $mail->ErrorInfo);
}
} catch (Exception $e) {JError::raiseWarning( 'SOME_ERROR_CODE', $e->getMessage());}
最佳答案
不要尝试让 PHPMailer 延迟发送,而是将您的电子邮件详细信息添加到数据库表中。然后编写一个 cron 作业来检查表中是否有需要发送的电子邮件。
关于php - 如何使用 PHPMailer 延迟发送邮件多天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37424609/