程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> ECMall如何支持SSL連接郵件服務器的配置

ECMall如何支持SSL連接郵件服務器的配置

編輯:關於PHP編程

首先,主要是ecmall使用的phpmailer版本太低,不支持加密連接。

然後,得對相應代碼做一定調整。

1. 覆蓋phpmailer

請從附件進行下載:

 http://files.cnblogs.com/x3d/ecmall_phpmailer_lib.zip

2. 改造lib

涉及到兩個lib:mail.lib.php 、mail_quequ.lib.php

在這兩個類的構造函數中,增加一個參數傳遞。如Mailer

function __construct($from, $email, $protocol, $host = '', $port = '', $user = '', $pass = '', $SMTPSecure = false)//增加$SMTPSecure
    {
        $this->Mailer($from, $email, $protocol, $host, $port, $user, $pass, $SMTPSecure);
    }

    function Mailer($from, $email, $protocol, $host = '', $port = '', $user = '', $pass = '', $SMTPSecure = false)
....

MailQueue中同理。

 

3. 封裝調用函數

global.lib.php 約300行

function &get_mailer()中增加一行:

$secure   = Conf::get('email_ssl');//增加這一行
        $mailer = new Mailer($sender, $from, $protocol, $host, $port, $username, $password, $secure);//同時傳遞參數

 

4. 調整後台email設置界面,增加相關設置項

後台模板:setting.email_setting.html 增加一個配置項

<tr>
                <th class="paddingT15">
                    郵件服務器加密方式:</th>
                <td class="paddingT15 wordSpacing5">
                    {html_radios name="email_ssl" options=$email_ssl checked=$setting.email_ssl}
                    <label class="field_notice">此功能要求您的php必須支持OpenSSL模塊, 如果您要使用此功能,請聯系您的空間商確認支持此模塊</label>
                </td>
            </tr>

 

同時,修改郵件測試的參數傳遞

<script type="text/javascript">
$(function(){
    $('#send_test_email').click(send_test_email);
});
function send_test_email(){
    var email_type = $('input[name="email_type"]:checked').val();
    var email_ssl = $('input[name="email_ssl"]:checked').val();//增加這一行
    $.ajax({
        type:"POST",
        url:"index.php",
        data:'app=setting&act=send_test_email&email_type='+email_type+'&email_host='+$("#email_host").val()+'&email_port='+$("#email_port").val()+'&email_addr='+$("#email_addr").val()+'&email_id='+$("#email_id").val()+'&email_pass='+$("#email_pass").val()+'&email_test='+$("#email_test").val()+'&email_ssl='+email_ssl,
        dataType:"json",
        success:function(data){
            if(data.done){
            alert(data.msg);
            }
            else{
                alert(data.msg);
            }
        },
        error: function(){alert('{$lang.mail_send_failure}');}
    });
}
</script>

然後還需要修改setting.app.php

/**
     *    EMAIL 設置
     *
     *    @author    Hyber
     *    @return    void
     */
    function email_setting()
    {
        $model_setting = &af('settings');
        $setting = $model_setting->getAll(); //載入系統設置數據
        if (!IS_POST)
        {
            $this->assign('setting', $setting);
            $this->assign('mail_type', array(
                MAIL_PROTOCOL_SMTP  => Lang::get('smtp'),
                MAIL_PROTOCOL_LOCAL => Lang::get('email'),
            ));
        //增加 $this->assign('email_ssl', array( 0 => Lang::get('no'), 1 => 'SSL', 2 => 'TLS', )); $this->display('setting.email_setting.html'); } else { $data['email_type'] = $_POST['email_type']; $data['email_host'] = $_POST['email_host']; $data['email_ssl'] = $_POST['email_ssl'];//增加 $data['email_port'] = $_POST['email_port']; $data['email_addr'] = $_POST['email_addr']; $data['email_id'] = $_POST['email_id']; $data['email_pass'] = $_POST['email_pass']; $data['email_test'] = $_POST['email_test']; $model_setting->setAll($data); $this->show_message('edit_email_setting_successed'); } }

以及測試郵件方法。

function send_test_email()
    {
        if (IS_POST)
        {
            $email_from = Conf::get('site_name');
            $email_type = $_POST['email_type'];
            $email_host = $_POST['email_host'];
            $email_ssl = $_POST['email_ssl'];//增加
            $email_port = $_POST['email_port'];
            $email_addr = $_POST['email_addr'];
            $email_id   = $_POST['email_id'];
            $email_pass = $_POST['email_pass'];
            $email_test = $_POST['email_test'];
            $email_subject = Lang::get('email_subjuect');
            $email_content = Lang::get('email_content');

            /* 使用mailer類 */
            import('mailer.lib');
            $mailer = new Mailer($email_from, $email_addr, $email_type, $email_host, $email_port, $email_id, $email_pass, $email_ssl);//增加
            $mail_result = $mailer->send($email_test, $email_subject, $email_content, CHARSET, 1);
            if ($mail_result)
            {
                $this->json_result('', 'mail_send_succeed');
            }
            else
            {
                $this->json_error('mail_send_failure', implode("\n", $mailer->errors));
            }
        }
        else
        {
            $this->show_warning('Hacking Attempt');
        }
    }

 

tls方式沒有測試過。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved