php - 如何使用 PHPMailer 延迟发送邮件多天?

标签 php email joomla delay phpmailer

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

所以我不是在寻找 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/

相关文章:

php - SQL CONCAT 如果列不为空

php - 如何覆盖 Doctrine 中的现有实体?

html - Web Outlook 中超链接的颜色

php - 将 SQL 语句转换为 Joomla 格式时遇到问题

php - Joomla Jdatabase 中 WHERE IN 的正确语法

php - joomla .htaccess 中的重写规则不起作用

php - 表布局 - foreach

php - 使用 "Simple HTML DOM"获取两个跨度之间的文本

html - 格式化电子邮件布局问题 Outlook 2013 - Windows 7

node.js - 电子邮件已验证,但我仍然无法使用 Amazon SES 发送电子邮件