如何延迟使用PHPMailer发送邮件数天?

如何延迟使用PHPMailer发送邮件数天?,php,email,joomla,delay,phpmailer,Php,Email,Joomla,Delay,Phpmailer,我正在尝试为我们的图书馆创建一个邮件系统。当人们需要一本书时,他们会收到一封电子邮件。不过,我希望他们也能在交工日期前一天收到一封电子邮件 所以,我不是在寻找一个睡眠脚本代码,我在寻找一个可以在服务器上存储数据直到交到日期的代码 我在我们的网站上使用Joomla 3.5.1,这是PHP编译器的代码: jimport('joomla.mail.mail'); try{ $mail = new PHPMailer(); $body = $mailm

我正在尝试为我们的图书馆创建一个邮件系统。当人们需要一本书时,他们会收到一封电子邮件。不过,我希望他们也能在交工日期前一天收到一封电子邮件

所以,我不是在寻找一个睡眠脚本代码,我在寻找一个可以在服务器上存储数据直到交到日期的代码

我在我们的网站上使用Joomla 3.5.1,这是PHP编译器的代码:

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作业,检查表中是否有需要发送的电子邮件。

谢谢!请求书本时,数据库会自动更新。我明天会去查cron jobs,没想到这么快就能得到答案!您的请求与当前借阅的图书有关?如果您确实记录了每个请求/预订,那么您可以每天进行投票。”所有明天到期的图书请求。对于每个请求,您可以记录请求日期和图书密钥。如果这本书没有按时归还,那可能会很烦人。也许最好在还书时才发电子邮件。