Ejemplo n.º 1
0
function email_send_message_to_user($to_uid, $from_uid, $subject, $message_body, $use_email_addr)
{
    if (!is_numeric($to_uid)) {
        return false;
    }
    if (!is_numeric($from_uid)) {
        return false;
    }
    if (!($to_user = user_get($to_uid))) {
        return false;
    }
    if (!($from_user = user_get($from_uid))) {
        return false;
    }
    if (!($transport = Swift_TransportFactory::get())) {
        return false;
    }
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_MessageBeehive::newInstance();
    if (!email_address_valid($to_user['EMAIL'])) {
        return false;
    }
    $forum_name = word_filter_apply(forum_get_setting('forum_name', null, 'A Beehive Forum'), $to_uid, true);
    $recipient = word_filter_apply(format_user_name($to_user['LOGON'], $to_user['NICKNAME']), $to_uid, true);
    $sent_from = word_filter_apply(format_user_name($from_user['LOGON'], $from_user['NICKNAME']), $to_uid, true);
    $message->setTo($to_user['EMAIL'], $recipient);
    if ($use_email_addr) {
        $message->setFrom($from_user['EMAIL'], $sent_from);
    }
    $message->setSubject($subject);
    $message->setBody(sprintf("%1\$s\n\n%2\$s", word_filter_apply(strip_tags($message_body), $to_uid, true), wordwrap(sprintf(gettext("This message was sent from %1\$s by %2\$s"), $forum_name, $sent_from))));
    $message->addPart(sprintf("<p>%1\$s</p><p>%2\$s</p>", word_filter_apply(strip_tags($message_body), $to_uid, true), wordwrap_html(sprintf(gettext("This message was sent from %1\$s by %2\$s"), $forum_name, $sent_from))), 'text/part');
    return $mailer->send($message);
}
Ejemplo n.º 2
0
function email_send_message_to_user($tuid, $fuid, $subject, $message_body, $use_email_addr)
{
    // Validate function arguments
    if (!is_numeric($tuid)) {
        return false;
    }
    if (!is_numeric($fuid)) {
        return false;
    }
    // Get the to user details
    if (!($to_user = user_get($tuid))) {
        return false;
    }
    // Get the to user details
    if (!($from_user = user_get($fuid))) {
        return false;
    }
    // Get the Swift Mailer Transport
    if (!($transport = Swift_TransportFactory::get())) {
        return false;
    }
    //Create the Mailer using the returned Transport
    $mailer = Swift_Mailer::newInstance($transport);
    // Create a new message
    $message = Swift_MessageBeehive::newInstance();
    // Validate the email address before we continue.
    if (!email_address_valid($to_user['EMAIL'])) {
        return false;
    }
    // Get the forum name, subject, recipient, author, thread title and generate
    // the messages link. Pass all of them through the recipient's word filter.
    $forum_name = word_filter_apply(forum_get_setting('forum_name', null, 'A Beehive Forum'), $tuid, true);
    $recipient = word_filter_apply(format_user_name($to_user['LOGON'], $to_user['NICKNAME']), $tuid, true);
    $sent_from = word_filter_apply(format_user_name($from_user['LOGON'], $from_user['NICKNAME']), $tuid, true);
    // Word filter the message to be sent.
    $message_body = word_filter_apply($message_body, $tuid, true);
    // Add the Sent By footer to the message.
    $message_body .= "\r\n\r\n" . wordwrap(sprintf(gettext("This message was sent from %s by %s"), $forum_name, $sent_from));
    // Add the recipient
    $message->setTo($to_user['EMAIL'], $recipient);
    // Set the from recipient
    if ($use_email_addr) {
        $message->setFrom($from_user['EMAIL'], $sent_from);
    }
    // Set the subject
    $message->setSubject($subject);
    // Set the message body
    $message->setBody($message_body);
    // Send the email
    return $mailer->send($message) > 0;
}