电子邮件动态内容在foreach中的第一个循环值中变得重复

时间:2019-04-03 06:40:17

标签: php codeigniter-3

我想发送邮件给多个用户,数据在我的数组中不是重复的,并且每个循环中的每个循环都发生了变化,但问题是发送给用户的电子邮件包含类似的信息,这是在第一次循环中出现的

例如-如果数组为

stdClass Object
(
    [ID] => 346
    [request_by] => 43
    [approved_by] => 31
    [request_month] => 2019-03
    [objects] => {"43":{"31":0}}
    [request_by_name] => Q
    [approved_by_name] => E
    [email] => q@gmail.com
)

stdClass Object
(
    [ID] => 348
    [request_by] => 35
    [approved_by] => 31
    [request_month] => 2019-03
    [objects] => {"35":{"31":0}}
    [request_by_name] => V
    [approved_by_name] => E
    [email] => q@gmail.com
)

第一封邮件将与内容Q一起发送给E 第二封邮件与第一封邮件相同,而内容必须类似于- 内容V向E发送了一封电子邮件

请检查以下代码以检查问题。

$email_template = $email_template->row();
foreach ($approvalData as $key => $value) {
    $email = $value->email;
    // pr($value);
    $message_id_hash = md5(rand(1,100000) . $value->email . time());
    $url = base_url()."work/index/$value->request_by/$value->ID";
    $request_by = $value->request_by_name;
    $approved_by = $value->approved_by_name;
    $email_template->message = $this->common->replace_keywords(array(
        "[REQUESTER_NAME]" => $request_by,
        "[REQUEST_RECEIVER_NAME]" => $approved_by,
        "[SITE_URL]" => site_url(),
        "[MONTH]" => $period,
        "[APPROVAL_LINK]" => $url
        ),
    $email_template->message);
    $headers = array(
        "Message-ID" => $message_id_hash
        );
    $subject = "Approve request.";
    // $this->common->send_email($subject, $email_template->message, $email, $headers);
    // echo "mail send from $value->request_by_name to $value->approved_by_name";
}

1 个答案:

答案 0 :(得分:0)

尝试在foreach循环内的行下方移动。

每次发送电子邮件时都需要重置$email_template

$email_template = $email_template->row();