我正在尝试为我们的图书馆创建邮件系统。人们在要求出书时会收到一封电子邮件。但是,我希望他们在递交日期前一天收到一封电子邮件。
所以我没有找到睡眠脚本代码,我正在寻找可以将数据存储在服务器上的代码,直到递交日期为止。
我在我们的网站上使用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());}
答案 0 :(得分:2)
不要试图让PHPMailer延迟发送,而是将您的电子邮件详细信息添加到数据库表中。然后编写一个cron作业,检查表格中是否有需要发送的电子邮件。