Exemplo n.º 1
0
function osc_sendMail($params)
{
    if (key_exists('add_bcc', $params)) {
        if (!is_array($params['add_bcc']) && $params['add_bcc'] != '') {
            $params['add_bcc'] = array($params['add_bcc']);
        }
    }
    require_once osc_lib_path() . 'phpmailer/class.phpmailer.php';
    if (osc_mailserver_pop()) {
        require_once osc_lib_path() . 'phpmailer/class.pop3.php';
        $pop = new POP3();
        $pop->Authorise(isset($params['host']) ? $params['host'] : osc_mailserver_host(), isset($params['port']) ? $params['port'] : osc_mailserver_port(), 30, isset($params['username']) ? $params['username'] : osc_mailserver_username(), isset($params['username']) ? $params['username'] : osc_mailserver_username(), 0);
    }
    $mail = new PHPMailer(true);
    try {
        $mail->CharSet = 'utf-8';
        if (osc_mailserver_auth()) {
            $mail->IsSMTP();
            $mail->SMTPAuth = true;
        } else {
            if (osc_mailserver_pop()) {
                $mail->IsSMTP();
            }
        }
        $mail->SMTPSecure = isset($params['ssl']) ? $params['ssl'] : osc_mailserver_ssl();
        $mail->Username = isset($params['username']) ? $params['username'] : osc_mailserver_username();
        $mail->Password = isset($params['password']) ? $params['password'] : osc_mailserver_password();
        $mail->Host = isset($params['host']) ? $params['host'] : osc_mailserver_host();
        $mail->Port = isset($params['port']) ? $params['port'] : osc_mailserver_port();
        $mail->From = isset($params['from']) ? $params['from'] : osc_contact_email();
        $mail->FromName = isset($params['from_name']) ? $params['from_name'] : osc_page_title();
        $mail->Subject = isset($params['subject']) ? $params['subject'] : '';
        $mail->Body = isset($params['body']) ? $params['body'] : '';
        $mail->AltBody = isset($params['alt_body']) ? $params['alt_body'] : '';
        $to = isset($params['to']) ? $params['to'] : '';
        $to_name = isset($params['to_name']) ? $params['to_name'] : '';
        if (key_exists('add_bcc', $params)) {
            foreach ($params['add_bcc'] as $bcc) {
                $mail->AddBCC($bcc);
            }
        }
        if (isset($params['reply_to'])) {
            $mail->AddReplyTo($params['reply_to']);
        }
        if (isset($params['attachment'])) {
            $mail->AddAttachment($params['attachment']);
        }
        $mail->IsHTML(true);
        $mail->AddAddress($to, $to_name);
        $mail->Send();
        return true;
    } catch (phpmailerException $e) {
        error_log("phpmailerException in osc_sendMail() Error: " . $mail->ErrorInfo, 0);
        return false;
    } catch (Exception $e) {
        error_log("Exception in osc_sendMail() Error" . $mail->ErrorInfo, 0);
        return false;
    }
    return false;
}
Exemplo n.º 2
0
?>
 name="mailserver_auth" value="1" />
                                    <?php 
_e('SMTP authentication enabled');
?>
</div>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-label"><?php 
_e('POP');
?>
</div>
                                <div class="form-controls">
                                    <div class="form-label-checkbox"><input type="checkbox" <?php 
echo osc_mailserver_pop() ? 'checked="checked"' : '';
?>
 name="mailserver_pop" value="1" />
                                    <?php 
_e('Use POP before SMTP');
?>
</div>
                                </div>
                            </div>
                            <div class="form-actions">
                                <input type="submit" id="save_changes" value="<?php 
echo osc_esc_html(__('Save changes'));
?>
" class="btn btn-submit" />
                            </div>
                        </div>
Exemplo n.º 3
0
?>
</small>
                                    </p>
                                    <p>
                                        <input style="height: 20px; padding-left: 4px;padding-top: 4px;" type="checkbox" <?php 
echo osc_mailserver_auth() ? 'checked="true"' : '';
?>
 name="mailserver_auth" id="mailserver_auth" />
                                        <label for="mailserver_auth"><?php 
_e('Enable SMTP authentication');
?>
</label>
                                    </p>
                                    <p>
                                        <input style="height: 20px; padding-left: 4px;padding-top: 4px;" type="checkbox" <?php 
echo osc_mailserver_pop() ? 'checked="true"' : '';
?>
 name="mailserver_pop" id="mailserver_pop" />
                                        <label for="mailserver_pop"><?php 
_e('Use a POP before SMTP');
?>
</label>
                                    </p>
                                </fieldset>
                            </div>

                            <div style="float: left; width: 50%;">
                                <fieldset>
                                    <legend><?php 
_e('Help');
?>
Exemplo n.º 4
0
function osc_sendMail($params)
{
    // DO NOT send mail if it's a demo
    if (defined('DEMO')) {
        return false;
    }
    $mail = new PHPMailer(true);
    $mail->ClearAddresses();
    $mail->ClearAllRecipients();
    $mail->ClearAttachments();
    $mail->ClearBCCs();
    $mail->ClearCCs();
    $mail->ClearCustomHeaders();
    $mail->ClearReplyTos();
    $mail = osc_apply_filter('init_send_mail', $mail, $params);
    if (osc_mailserver_pop()) {
        require_once osc_lib_path() . 'phpmailer/class.pop3.php';
        $pop = new POP3();
        $pop3_host = osc_mailserver_host();
        if (array_key_exists('host', $params)) {
            $pop3_host = $params['host'];
        }
        $pop3_port = osc_mailserver_port();
        if (array_key_exists('port', $params)) {
            $pop3_port = $params['port'];
        }
        $pop3_username = osc_mailserver_username();
        if (array_key_exists('username', $params)) {
            $pop3_username = $params['username'];
        }
        $pop3_password = osc_mailserver_password();
        if (array_key_exists('password', $params)) {
            $pop3_password = $params['password'];
        }
        $pop->Authorise($pop3_host, $pop3_port, 30, $pop3_username, $pop3_password, 0);
    }
    if (osc_mailserver_auth()) {
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
    } else {
        if (osc_mailserver_pop()) {
            $mail->IsSMTP();
        }
    }
    $smtpSecure = osc_mailserver_ssl();
    if (array_key_exists('password', $params)) {
        $smtpSecure = $params['ssl'];
    }
    if ($smtpSecure != '') {
        $mail->SMTPSecure = $smtpSecure;
    }
    $stmpUsername = osc_mailserver_username();
    if (array_key_exists('username', $params)) {
        $stmpUsername = $params['username'];
    }
    if ($stmpUsername != '') {
        $mail->Username = $stmpUsername;
    }
    $smtpPassword = osc_mailserver_password();
    if (array_key_exists('password', $params)) {
        $smtpPassword = $params['password'];
    }
    if ($smtpPassword != '') {
        $mail->Password = $smtpPassword;
    }
    $smtpHost = osc_mailserver_host();
    if (array_key_exists('host', $params)) {
        $smtpHost = $params['host'];
    }
    if ($smtpHost != '') {
        $mail->Host = $smtpHost;
    }
    $smtpPort = osc_mailserver_port();
    if (array_key_exists('port', $params)) {
        $smtpPort = $params['port'];
    }
    if ($smtpPort != '') {
        $mail->Port = $smtpPort;
    }
    $from = osc_mailserver_mail_from();
    if (empty($from)) {
        $from = 'osclass@' . osc_get_domain();
        if (array_key_exists('from', $params)) {
            $from = $params['from'];
        }
    }
    $from_name = osc_mailserver_name_from();
    if (empty($from_name)) {
        $from_name = osc_page_title();
        if (array_key_exists('from_name', $params)) {
            $from_name = $params['from_name'];
        }
    }
    $mail->From = osc_apply_filter('mail_from', $from, $params);
    $mail->FromName = osc_apply_filter('mail_from_name', $from_name, $params);
    $to = $params['to'];
    $to_name = '';
    if (array_key_exists('to_name', $params)) {
        $to_name = $params['to_name'];
    }
    if (!is_array($to)) {
        $to = array($to => $to_name);
    }
    foreach ($to as $to_email => $to_name) {
        try {
            $mail->addAddress($to_email, $to_name);
        } catch (phpmailerException $e) {
            continue;
        }
    }
    if (array_key_exists('add_bcc', $params)) {
        if (!is_array($params['add_bcc']) && $params['add_bcc'] != '') {
            $params['add_bcc'] = array($params['add_bcc']);
        }
        foreach ($params['add_bcc'] as $bcc) {
            try {
                $mail->AddBCC($bcc);
            } catch (phpmailerException $e) {
                continue;
            }
        }
    }
    if (array_key_exists('reply_to', $params)) {
        try {
            $mail->AddReplyTo($params['reply_to']);
        } catch (phpmailerException $e) {
            //continue;
        }
    }
    $mail->Subject = $params['subject'];
    $mail->Body = $params['body'];
    if (array_key_exists('attachment', $params)) {
        if (!is_array($params['attachment']) || isset($params['attachment']['path'])) {
            $params['attachment'] = array($params['attachment']);
        }
        foreach ($params['attachment'] as $attachment) {
            try {
                if (is_array($attachment)) {
                    if (isset($attachment['path']) && isset($attachment['name'])) {
                        $mail->AddAttachment($attachment['path'], $attachment['name']);
                    }
                } else {
                    $mail->AddAttachment($attachment);
                }
            } catch (phpmailerException $e) {
                continue;
            }
        }
    }
    $mail->CharSet = 'utf-8';
    $mail->IsHTML(true);
    $mail = osc_apply_filter('pre_send_mail', $mail, $params);
    // send email!
    try {
        $mail->Send();
    } catch (phpmailerException $e) {
        return false;
    }
    return true;
}