好的,我在我的网站上注册了通过电子邮件激活帐户,并且我注意到并非所有会员都激活了他们的帐户,所以如果帐户在注册后7天内未激活,我需要自动向他们发送电子邮件
我希望每天运行一次此代码但是如果它被发送给一个用户,那么下次它不应该再次向同一个用户发送电子邮件以避免垃圾邮件
这是我到目前为止所写的内容,但我不知道如何实现其余的
$query = "SELECT * FROM members WHERE active !='Yes' AND (joined > DATE_SUB(NOW(), INTERVAL 7 DAY))";
$stmt->execute();
$result = $stmt->fetch();
foreach ($result as $row) {
$id = $row['member_id'];
$to = $row['email'];
$activation = $row['active'];
$subject = "Account Activation";
$body = "<p><img src='".DIR."images/logo.png' alt='logo'></p> <p>Hello,</p><p>Thank you for registering at ".SITEURL.".</p>
<p>It seems you have still not activated you account, to activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activation'>CLICK HERE</a>. If you do not activate your account within 7 days your account will automatically get deleted. </p>
<p>Regards,<br/>".SITEURL."<br/><a href='tel:".SITEMOBILE."'>".SITEMOBILE."</a></p>
<p align='center'><small><font color='red'>This is an automated message, please do not reply to this.</font></small></p>";
$mail = new Mail();
$mail->setFrom(REGEMAIL);
$mail->addAddress($to);
$mail->subject($subject);
$mail->body($body);
$mail->send();
}
非常感谢您的时间和帮助
答案 0 :(得分:-1)
您的上述代码没问题。它运作良好。您需要在“members”表中创建一个新列,如“sent_activation_email”,然后运行此字段的cronjob应该更新。
所以你的检索查询修改如下:
$query = "SELECT * FROM members WHERE active !='Yes' AND (joined > DATE_SUB(NOW(), INTERVAL 7 DAY)) AND sent_activation_email != 0";
在你的$ mail-&gt; send()函数之后写一个更新查询。
.......
$mail->subject($subject);
$mail->body($body);
$mail->send();
$sql = mysql_query("UPDATE `members` SET `sent_activation_email` = '1' WHERE `id` = ".$row['member_id'].") ";