【问题标题】:how to send auto email to members who did not activate account如何向未激活帐户的成员发送自动电子邮件
【发布时间】:2016-11-07 18:16:12
【问题描述】:

好的,我在通过电子邮件激活帐户的网站上进行了注册,我注意到并非所有成员都激活了他们的帐户,因此如果帐户在注册后 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();

        }

非常感谢您的时间和帮助

【问题讨论】:

  • 这似乎是一个 cronjob 的问题
  • 还可以根据用户的尊重ID和激活哈希查询向用户发送电子邮件怎么做?
  • 例如在您的数据库中创建一个表,您可以在其中记录发送的电子邮件
  • 以及如何使用while循环发送邮件?
  • 是的,但是您需要像现在一样获取不止一行($row = $stmt-&gt;fetch(); 将始终返回最多一行)

标签: php mysql cron


【解决方案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->send() 函数之后写一个更新查询。

.......

$mail->subject($subject);
$mail->body($body);
$mail->send();

$sql = mysql_query("UPDATE `members` SET `sent_activation_email` = '1' WHERE `id` = ".$row['member_id'].") ";

【讨论】:

  • @johram pong - 向上箭头
猜你喜欢
  • 2012-04-27
  • 2011-01-02
  • 2018-08-19
  • 1970-01-01
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
相关资源
最近更新 更多