doumeng06063991 2015-01-15 08:06
浏览 15

Php Mail发送给mysqli中的所有管理员用户

Hey i have issue with mail system. I would send to all admin users en email but it just takes the first one and the others not

$adminUsers = User::getAdminUsers();
    foreach($adminUsers as $adminUser){
        $to  = $adminUser->getEmail(); 
        // sujet
        $subject = 'Boîte à idées - Nouvelle idée';

        // message
        $user = new User($userId);
        $link = "http://idees.pcprofi.ch/pages/login.php";
        $message = '
        <html>
        <head>
          <title>Une nouvelle idée proposée</title>
        </head>
        <body>
          <p>Bonjour,</p>
          <p>
            Une nouvelle idée a été proposée par ' . $user->getName() . ' '
                . '. Vous pourrez la consulter une fois connecté à la '
                . '<a href="' . $link . '">Boîte à idées</a>.
          </p>
          <p> 
            Salutations.
          </p>
        </body>
        </html>
        ';

        // nécessaire pour un mail HTML
        $headers  = 'MIME-Version: 1.0' . "
";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

        // informations additionnels
        $headers .= "To: " .  $adminUser->getName(); " 
";
        $headers .= " " . $adminUser->getEmail(); "
";
        $headers .= ' From: Boîte à idée <bai@test.com>' . "
";

        // Envoi du mail
        mail($to, $subject, $message, $headers);

And my function to get the admin users is this .

public static function getAdminUsers(){
    $db = new Database();
    $mysqli = $db->getConnect();
    $statement = "SELECT `id` FROM `users` WHERE `admin`= 1";
    $sql = mysqli_query($mysqli, $statement);
    $users = [];

    while($result = (mysqli_fetch_array($sql))){
        $id = $result['id'];
        $user = new User($id);
        $users[] = $user;
    }
    return $users;
}

Thanks allready in advance. I hope you know how to help me :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改