<?php
    //project email notifications
    $notifications = $db->run("SELECT * FROM user WHERE superAdmin = 1");

    $name = $user['name'];

    try {
        $dMessageTransport = (new Swift_SmtpTransport(EMAIL_SMTP, 587));
        $dMessageMailer    = new Swift_Mailer($dMessageTransport);
        $dMessageSubject   = EMAIL_FROM_NAME." - $name Visited Portal";
        $dMessage          = (new Swift_Message($dMessageSubject));

        // $dTo[EMAIL_ADMIN_ADDRESS] = EMAIL_ADMIN_NAME;
        foreach ( $notifications as $notification ) {
            $dTo[$notification['email']] = $notification['name'];
        }

        ob_start();
?>
            <h3><?php echo $name; ?> Visited Portal</h3>
            <p>Time: <?php echo date('Y-m-d H:i:s', time()); ?></p>
            <p>Email: <?php echo $user['email']; ?></p>
            <p>IP: <?php echo $auth_token['ip']; ?></p>
            <p>Device: <?php echo $auth_token['ua']; ?></p>
<?php
        $dMessageHtml = ob_get_clean();

        $dMessage->setFrom([EMAIL_FROM_ADDRESS => EMAIL_FROM_NAME])
            ->setTo($dTo)
            ->setBody($dMessageHtml, 'text/html')
        ;

        $dMessageResult = $dMessageMailer->send($dMessage);
    } catch ( Exception $e ) {
        //log it, notify
    }
?>