Exemplo n.º 1
0
function osc_sendMail($params)
{
    require_once osc_lib_path() . 'phpmailer/class.phpmailer.php';
    $mail = new PHPMailer(true);
    try {
        $mail->CharSet = "utf-8";
        if (osc_mailserver_auth()) {
            $mail->IsSMTP();
            $mail->SMTPAuth = true;
        }
        $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 (isset($params['add_bbc'])) {
            $mail->AddBCC($params['add_bbc']);
        }
        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) {
        return false;
    } catch (Exception $e) {
        return false;
    }
    return false;
}
Exemplo n.º 2
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.º 3
0
</p>
                                    </div>
                                    <?php 
    }
}
?>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-label"><?php 
_e('SMTP');
?>
</div>
                                <div class="form-controls">
                                    <div class="form-label-checkbox"><input type="checkbox" <?php 
echo osc_mailserver_auth() ? 'checked="checked"' : '';
?>
 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 
Exemplo n.º 4
0
_e('Encryption');
?>
</label>
                                        <br/>
                                        <input style="height: 20px; padding-left: 4px;padding-top: 4px;" type="text"  name="mailserver_ssl" id="mailserver_ssl" value="<?php 
echo osc_mailserver_ssl();
?>
" />
                                        <small><?php 
_e('Options: blank, ssl or tls');
?>
</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');
?>
Exemplo n.º 5
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;
}