Esempio n. 1
0
/**
 * util_send_message() - Send email
 * This function should be used in place of the PHP mail() function
 *
 * @param		string	The email recipients address
 * @param		string	The email subject
 * @param		string	The body of the email message
 * @param		string	The optional email sender address.  Defaults to 'noreply@'
 * @param		string	The addresses to blind-carbon-copy this message
 * @param		string	The optional email sender name. Defaults to ''
 * @param 		boolean	Whether to send plain text or html email
 *
 */
function util_send_message($to, $subject, $body, $from = '', $BCC = '', $sendername = '', $extra_headers = '', $send_html_email = false)
{
    global $sys_bcc_all_email_address, $sys_sendmail_path;
    if (!$to) {
        $to = 'noreply@' . $GLOBALS['sys_default_domain'];
    }
    if (!$from) {
        $from = 'noreply@' . $GLOBALS['sys_default_domain'];
    }
    $charset = _('UTF-8');
    if (!$charset) {
        $charset = 'UTF-8';
    }
    $body2 = '';
    if ($extra_headers) {
        $body2 .= $extra_headers . "\n";
    }
    $body2 .= "To: {$to}" . "\nFrom: " . util_encode_mailaddr($from, $sendername, $charset);
    if (!empty($sys_bcc_all_email_address)) {
        $BCC .= ",{$sys_bcc_all_email_address}";
    }
    if (!empty($BCC)) {
        $body2 .= "\nBCC: {$BCC}";
    }
    $send_html_email ? $type = "html" : ($type = "plain");
    $body2 .= "\nSubject: " . util_encode_mimeheader($subject, $charset) . "\nContent-type: text/{$type}; charset={$charset}" . "\n\n" . util_convert_body($body, $charset);
    if (!$sys_sendmail_path) {
        $sys_sendmail_path = "/usr/sbin/sendmail";
    }
    exec("/bin/echo " . util_prep_string_for_sendmail($body2) . " | " . $sys_sendmail_path . " -f'{$from}' -t -i > /dev/null 2>&1 &");
    // WARNING : popen commented code probably brought some trouble, we will use the pipe method as we were before
    /*if (!$handle = popen($sys_sendmail_path." -f'$from' -t -i", "w")) {
              echo "<p>Error: cannot run '$sys_sendmail_path' - mail not sent</p>\n";
      } else {
              fwrite($handle, util_prep_string_for_sendmail($body2));
              pclose($handle);
      }*/
}
Esempio n. 2
0
 } else {
     if ($add) {
         //inserting a new diary entry
         $sql = "INSERT INTO user_diary (user_id,date_posted,summary,details,is_public) VALUES " . "('" . user_getid() . "','" . time() . "','" . htmlspecialchars($summary) . "','" . htmlspecialchars($details) . "','{$is_public}')";
         $res = db_query($sql);
         if ($res && db_affected_rows($res) > 0) {
             $feedback .= ' Item Added ';
             if ($is_public) {
                 //send an email if users are monitoring
                 $sql = "SELECT users.email from user_diary_monitor,users " . "WHERE user_diary_monitor.user_id=users.user_id " . "AND user_diary_monitor.monitored_user='******'";
                 $result = db_query($sql);
                 $rows = db_numrows($result);
                 if ($result && $rows > 0) {
                     $tolist = implode(result_column_to_array($result), ', ');
                     $body = "To: noreply@{$GLOBALS['sys_default_domain']}" . "\nBCC: {$tolist}" . "\nSubject: [ SF User Notes: " . user_getrealname(user_getid()) . "] " . stripslashes($summary) . "\n\n" . util_line_wrap(stripslashes($details)) . "\n\n______________________________________________________________________" . "\nYou are receiving this email because you elected to monitor this user." . "\nTo stop monitoring this user, login to " . $GLOBALS['sys_default_name'] . " and visit: " . "\nhttp://{$GLOBALS['sys_default_host']}/developer/monitor.php?user="******"/bin/echo \"" . util_prep_string_for_sendmail($body) . "\" | {$GLOBALS['sys_sendmail_path']} -fnoreply@{$GLOBALS['sys_default_domain']} -t -i >& /dev/null &");
                     $feedback .= " email sent - ({$rows}) people monitoring ";
                 } else {
                     $feedback .= ' email not sent - no one monitoring ';
                     echo db_error();
                 }
             } else {
                 //don't send an email to monitoring users
                 //since this is a private note
             }
         } else {
             $feedback .= ' Error Adding Item ';
             echo db_error();
         }
     }
 }
Esempio n. 3
0
function mail_followup($support_id, $more_addresses = false)
{
    global $sys_datefmt, $feedback;
    /*
    	Send a message to the person who opened this support and the person it is assigned to
    */
    $sql = "SELECT support.priority,support.group_id,support.support_id,support.summary," . "support_status.status_name,support_category.category_name,support.open_date, " . "users.email,user2.email AS assigned_to_email " . "FROM support,users,users user2,support_status,support_category " . "WHERE user2.user_id=support.assigned_to " . "AND support.support_status_id=support_status.support_status_id " . "AND support.support_category_id=support_category.support_category_id " . "AND users.user_id=support.submitted_by " . "AND support.support_id='{$support_id}'";
    $result = db_query($sql);
    if ($result && db_numrows($result) > 0) {
        /*
        	Set up the body
        */
        $body = "\n\nSupport Request #" . db_result($result, 0, 'support_id') . ", was updated on " . date($sys_datefmt, db_result($result, 0, 'open_date')) . "\nYou can respond by visiting: " . "\nhttp://" . $GLOBALS['sys_default_host'] . "/support/?func=detailsupport&support_id=" . db_result($result, 0, "support_id") . "&group_id=" . db_result($result, 0, "group_id") . "\n\nCategory: " . db_result($result, 0, 'category_name') . "\nStatus: " . db_result($result, 0, 'status_name') . "\nPriority: " . db_result($result, 0, 'priority') . "\nSummary: " . util_unconvert_htmlspecialchars(db_result($result, 0, 'summary'));
        $subject = "[Support #" . db_result($result, 0, "support_id") . "] " . util_unconvert_htmlspecialchars(db_result($result, 0, "summary"));
        /*      
        	get all the email addresses that have dealt with this request
        */
        $email_res = db_query("SELECT distinct from_email FROM support_messages WHERE support_id='{$support_id}'");
        $rows = db_numrows($email_res);
        if ($email_res && $rows > 0) {
            $mail_arr = result_column_to_array($email_res, 0);
            $emails = implode($mail_arr, ', ');
        }
        if ($more_addresses) {
            $emails .= ',' . $more_addresses;
        }
        /*
        	Now include the two most recent emails
        */
        $sql = "select * " . "FROM support_messages " . "WHERE support_id='{$support_id}' ORDER BY date DESC";
        $result2 = db_query($sql, 2);
        $rows = db_numrows($result2);
        if ($result && $rows > 0) {
            for ($i = 0; $i < $rows; $i++) {
                //get the first part of the email address
                $email_arr = explode('@', db_result($result2, $i, 'from_email'));
                $body .= "\n\nBy: " . $email_arr[0] . "\nDate: " . date($sys_datefmt, db_result($result2, $i, 'date')) . "\n\nMessage:" . "\n" . util_unconvert_htmlspecialchars(db_result($result2, $i, 'body')) . "\n\n----------------------------------------------------------------------";
            }
            $body .= "\nYou can respond by visiting: " . "\nhttp://{$GLOBALS['sys_default_host']}/support/?func=detailsupport&support_id=" . db_result($result, 0, 'support_id') . "&group_id=" . db_result($result, 0, 'group_id');
        }
        //attach the headers to the body
        $body = "To: noreply@{$GLOBALS['sys_default_domain']}" . "\nBCC: {$emails}" . "\nSubject: {$subject}" . $body;
        /*      
        	Send the email
        */
        exec("/bin/echo \"" . util_prep_string_for_sendmail($body) . "\" | {$GLOBALS['sys_sendmail_path']} -fnoreply@{$GLOBALS['sys_default_domain']} -t &");
        $feedback .= " Support Request Update Emailed ";
    } else {
        $feedback .= " Could Not Send Support Request Update ";
        echo db_error();
    }
}
Esempio n. 4
0
/**
 *	assumes $send_all_posts_to var is set up
 */
function handle_monitoring($forum_id, $msg_id)
{
    global $feedback, $send_all_posts_to;
    /*
    	Checks to see if anyone is monitoring this forum
    	If someone is, it sends them the message in email format
    */
    $sql = "SELECT users.email from forum_monitored_forums,users " . "WHERE forum_monitored_forums.user_id=users.user_id AND forum_monitored_forums.forum_id='{$forum_id}'";
    $result = db_query($sql);
    $rows = db_numrows($result);
    if ($result && $rows > 0 || $send_all_posts_to) {
        $tolist = $send_all_posts_to . ', ' . implode(result_column_to_array($result), ', ');
        $sql = "SELECT groups.unix_group_name,users.user_name,forum_group_list.forum_name," . "forum.group_forum_id,forum.thread_id,forum.subject,forum.date,forum.body " . "FROM forum,users,forum_group_list,groups " . "WHERE users.user_id=forum.posted_by " . "AND forum_group_list.group_forum_id=forum.group_forum_id " . "AND groups.group_id=forum_group_list.group_id " . "AND forum.msg_id='{$msg_id}'";
        $result = db_query($sql);
        if ($result && db_numrows($result) > 0) {
            $body = "To: noreply@{$GLOBALS['sys_default_domain']}" . "\nBCC: {$tolist}" . "\nSubject: [" . db_result($result, 0, 'unix_group_name') . " - " . db_result($result, 0, 'forum_name') . "] " . util_unconvert_htmlspecialchars(db_result($result, 0, 'subject')) . "\n\nRead and respond to this message at: " . "\nhttp://{$GLOBALS['sys_default_host']}/forum/message.php?msg_id=" . $msg_id . "\nBy: " . db_result($result, 0, 'user_name') . "\n\n" . util_line_wrap(util_unconvert_htmlspecialchars(db_result($result, 0, 'body'))) . "\n\n______________________________________________________________________" . "\nYou are receiving this email because you elected to monitor this forum." . "\nTo stop monitoring this forum, login to " . $GLOBALS['sys_default_name'] . " and visit: " . "\nhttp://{$GLOBALS['sys_default_host']}/forum/monitor.php?forum_id={$forum_id}";
            // echo "<pre>/bin/echo \"". util_prep_string_for_sendmail($body) ."\" | $GLOBALS[sys_sendmail_path] -fnoreply@$GLOBALS[sys_default_name] -t</pre>";
            exec("/bin/echo \"" . util_prep_string_for_sendmail($body) . "\" | {$GLOBALS['sys_sendmail_path']} -fnoreply@{$GLOBALS['sys_default_domain']} -t &");
            $feedback .= ' email sent - people monitoring ';
        } else {
            $feedback .= ' email not sent - people monitoring ';
            echo db_error();
        }
    } else {
        $feedback .= ' email not sent - no one monitoring ';
        echo db_error();
    }
}