【问题标题】:Send one email to each user with different content from database向每个用户发送一封电子邮件,其中包含来自数据库的不同内容
【发布时间】:2016-10-26 19:03:21
【问题描述】:

所以基本上我有以下表格:

users id - email - username - password

todo id - user_id - name - description - reminder - reminder_date

我想向每个用户发送一封电子邮件,通知他们当reminder_date = 'today' 时他们有一些任务要做。这将由 cron 作业处理。 问题是我已经设法提取了用​​户,我可以轻松地向这些用户发送电子邮件,但我还想在电子邮件正文中发送“todo.name”,以便他们知道当天的任务是什么。

到目前为止,我有以下内容:

$users = DB::select()->from('todo')->join('users', 'INNER')->on('todo.user_id', '=', 'users.id') ->where('todo.reminder', '=', 1)->and_where('reminder_date', '=', Date::formatted_time('now', 'Y-m-d'))->and_where('todo.status', '=', 'active') ->execute() ->as_array();

并带有以下内容:

$count = 0;
foreach ($users as $k => $v) {
            $count++;
            $allemails[] = $v['email'];
            $mailsUnique = array_unique($allemails);
        }

        $max = sizeof($mailsUnique);

        for ($i = 0; $i < $max; $i++) {
            foreach ($users as $k) {
                if ($mailsUnique[$i] == $k['email']) {
                  $task[$mailsUnique[$i]][] = $k['task'];
                } else {
              }
            }
          }

使用以下代码,我有一个多数组,其中包含每封电子邮件的每个任务。我似乎无法弄清楚如何使用与该用户对应的每个“任务名称”作为邮件正文向每个用户发送一封电子邮件。

例如:

array(2) (
    "someEmail.yyy@provider.com" => array(1) (
        0 => string(6) "Do something"         <--- Task Name
        1 => string(6) "Do something else"    <--- Task Name
    )
    "otherEmail@provider.com" => array(1) (
        0 => string(6) "aaaaaa"               <--- Task Name
    )
)

谢谢!

【问题讨论】:

    标签: php mysql kohana


    【解决方案1】:

    您可以使用key =&gt; value 循环遍历外部数组以提取电子邮件地址。它看起来像这样:

    foreach ( $array as $email => $tasks ) {
        foreach ( $tasks as $task ) {
            // send email to $email for each task or put together the list of tasks to put into one email below this loop.
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-21
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 2017-02-19
      • 2017-02-12
      • 1970-01-01
      相关资源
      最近更新 更多