欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ECMall支持SSL连接邮件服务器的配置方法详解

程序员文章站 2023-11-30 21:00:58
首先,主要是ecmall使用的phpmailer版本太低,不支持加密连接。 然后,得对相应代码做一定调整。 1. 覆盖phpmailer 请从附件进行下载:复制代码...

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

然后,得对相应代码做一定调整。

1. 覆盖phpmailer

请从附件进行下载:

复制代码 代码如下:

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(
=> lang::get('no'),
 => 'ssl',
 => '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方式没有测试过。