messenger::msg_email PHP Method

msg_email() public method

Send out emails
public msg_email ( )
    function msg_email()
    {
        global $config;
        if (empty($config['email_enable'])) {
            return false;
        }
        // Addresses to send to?
        if (empty($this->addresses) || empty($this->addresses['to']) && empty($this->addresses['cc']) && empty($this->addresses['bcc'])) {
            // Send was successful. ;)
            return true;
        }
        $use_queue = false;
        if ($config['email_package_size'] && $this->use_queue) {
            if (empty($this->queue)) {
                $this->queue = new queue();
                $this->queue->init('email', $config['email_package_size']);
            }
            $use_queue = true;
        }
        $contact_name = htmlspecialchars_decode($config['board_contact_name']);
        $board_contact = ($contact_name !== '' ? '"' . mail_encode($contact_name) . '" ' : '') . '<' . $config['board_contact'] . '>';
        if (empty($this->replyto)) {
            $this->replyto = $board_contact;
        }
        if (empty($this->from)) {
            $this->from = $board_contact;
        }
        $encode_eol = $config['smtp_delivery'] ? "\r\n" : PHP_EOL;
        // Build to, cc and bcc strings
        $to = $cc = $bcc = '';
        foreach ($this->addresses as $type => $address_ary) {
            if ($type == 'im') {
                continue;
            }
            foreach ($address_ary as $which_ary) {
                ${$type} .= (${$type} != '' ? ', ' : '') . ($which_ary['name'] != '' ? mail_encode($which_ary['name'], $encode_eol) . ' <' . $which_ary['email'] . '>' : $which_ary['email']);
            }
        }
        // Build header
        $headers = $this->build_header($to, $cc, $bcc);
        // Send message ...
        if (!$use_queue) {
            $mail_to = $to == '' ? 'undisclosed-recipients:;' : $to;
            $err_msg = '';
            if ($config['smtp_delivery']) {
                $result = smtpmail($this->addresses, mail_encode($this->subject), wordwrap(utf8_wordwrap($this->msg), 997, "\n", true), $err_msg, $headers);
            } else {
                $result = phpbb_mail($mail_to, $this->subject, $this->msg, $headers, PHP_EOL, $err_msg);
            }
            if (!$result) {
                $this->error('EMAIL', $err_msg);
                return false;
            }
        } else {
            $this->queue->put('email', array('to' => $to, 'addresses' => $this->addresses, 'subject' => $this->subject, 'msg' => $this->msg, 'headers' => $headers));
        }
        return true;
    }