query(" select u.`username`, u.`email` from `users` as u where u.`uid` in ( select `uid` from `permissions` where `rentalsadmin` = 1 ) "); // none? if ($sql->num($get_admins) == 0) return; // why waste time with shitty emails? require_once $libs_path . 'check_email.inc.php'; $email_validator = new EmailAddressValidator; // from headers $headers = array('From: Puttynuts Web Services '); // use plaintext otherwise if (strlen(strip_tags($message)) == strlen($message)) $headers[] = 'Content-type: text/plain'; if ($reply_to != '') $headers[] = 'Reply-to: '.$reply_to; // lines can't be more than 70 characters long $message = wordwrap($message, 70); // do them while (list($name, $email) = $sql->fetch_row($get_admins)) { // get them normal $name = stripslashes(trim($name)); $email = stripslashes(trim($email)); // make sure it doesn't fucking suck if (!$email_validator->check_email_address($email)) continue; // add some fun bits to the email $this_message = "Dear USURP admin {$name},\n\n" . $message; $this_message = $this_message . "\n\nRegards, USURP team"; // do it @mail($email, $subject, $this_message, implode("\r\n", $headers)); } $sql->free($get_admins); //....done? return true; } // send an email to a user function notify_user($user_id, $subject, $message, $reply_to = '') { global $ui, $sql, $libs_path; // shitty id? fuck it if (!ctype_digit($user_id)) return false; // get email and username if ($user_id == $ui->current_user_id()) { // avoid making a redundant sql query if we already know user's email $email = $ui->current_user_email(); $username = $ui->current_user_name(); } else { // otherwise get it $get_info = $sql->query("select `username`, `email` from `users` where `UID` = '$user_id' limit 1"); // not found? if ($sql->num($get_info) == 0) return false; // get info list($username, $email) = $sql->fetch_row($get_info); // get them normal.. $email = trim(stripslashes($email)); $username = trim(stripslashes($username)); } // make sure the email address is usable require_once $libs_path . 'check_email.inc.php'; $email_validator = new EmailAddressValidator; if (!$email_validator->check_email_address($email)) false; // deal with email headers $headers = array('From: Puttynuts Web Services '); // use plaintext otherwise if (strlen(strip_tags($message)) == strlen($message)) $headers[] = 'Content-type: text/plain'; if ($reply_to != '') $headers[] = 'Reply-to: '.$reply_to; // lines can't be more than 70 characters long $message = wordwrap($message, 70); // add some fun bits to the email $message = "Dear Puttynuts customer {$username},\n\n" . $message; $message = $message . "\n\nRegards, the Puttynuts team"; // run it if (!@mail($email, $subject, $message, implode("\r\n", $headers))) return false; // done return true; }