function cupid_email($profile)
{
    global $ret;
    global $data;
    global $site;
    $profile = (int) $profile;
    $match_min = (int) getParam("match_percent");
    $prof_arr = getProfileInfo($profile, true);
    if ((int) $prof_arr['ID'] <= 0) {
        return false;
    }
    $add = '';
    if ('all' != $prof_arr['LookingFor']) {
        $add = "AND `Sex` = '{$prof_arr['LookingFor']}' ";
    }
    $add .= "AND ( `LookingFor` = '{$prof_arr['Sex']}' OR `LookingFor` = 'all' )";
    $memb_res = db_res("SELECT ID, NickName, Email, EmailFlag\n\t\t\t\tFROM Profiles\n\t\t\t\tWHERE EmailNotify = 'NotifyMe' AND Status = 'Active' AND ID <> {$profile} {$add}");
    if (mysql_num_rows($memb_res) < 1) {
        return false;
    }
    while ($memb_arr = mysql_fetch_array($memb_res)) {
        $match = match_profiles($memb_arr['ID'], $profile);
        if ($match < $match_min) {
            // If the profile matches less then predefined
            // percent then go to next iteration (i.e. next profile)
            continue;
        }
        $message = getParam("t_CupidMail");
        $subject = getParam('t_CupidMail_subject');
        $subject = addslashes($subject);
        $recipient = $memb_arr['Email'];
        $headers = "From: {$site['title']} <{$site['email_notify']}>";
        $headers2 = "-f{$site['email_notify']}";
        $message = str_replace("<SiteName>", $site['title'], $message);
        $message = str_replace("<Domain>", $site['url'], $message);
        $message = str_replace("<RealName>", $memb_arr['NickName'], $message);
        $message = str_replace("<StrID>", $memb_arr['ID'], $message);
        $message = str_replace("<MatchProfileLink>", getProfileLink($prof_arr['ID']), $message);
        $message = addslashes($message);
        if ('Text' == $memb_arr['EmailFlag']) {
            $message = html2txt($message);
        }
        if ('HTML' == $memb_arr['EmailFlag']) {
            $headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html; charset=UTF-8\r\n" . $headers;
        }
        $sql = "INSERT INTO `NotifyQueue` SET `Email` = {$memb_arr['ID']}, Msg = 0, `From` = 'ProfilesMsgText', Creation = NOW(), MsgText = '{$message}', MsgSubj = '{$subject}'";
        $res = db_res($sql);
    }
    return true;
}
function getProfileMatch($memberID, $profileID)
{
    global $oTemplConfig;
    $match_n = match_profiles($memberID, $profileID);
    $ret = '';
    $ret .= DesignProgressPos(_t("_XX match", $match_n), $oTemplConfig->iProfileViewProgressBar, 100, $match_n);
    return $ret;
}