首頁 > 後端開發 > php教程 > ECMall如何支持SSL连接邮件服务器的配置_PHP教程

ECMall如何支持SSL连接邮件服务器的配置_PHP教程

WBOY
發布: 2016-07-13 10:29:38
原創
1106 人瀏覽過

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

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

1. 覆盖phpmailer

请从附件进行下载:

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

2. 改造lib

涉及到两个lib:mail.lib.php 、mail_quequ.lib.php

在这两个类的构造函数中,增加一个参数传递。如Mailer

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

    </span><span>function</span> Mailer(<span>$from</span>, <span>$email</span>, <span>$protocol</span>, <span>$host</span> = '', <span>$port</span> = '', <span>$user</span> = '', <span>$pass</span> = '', <span>$SMTPSecure</span> = <span>false</span><span>)
</span>....
登入後複製

MailQueue中同理。

3. 封装调用函数

global.lib.php 约300行

function &get_mailer()中增加一行:

<span>$secure</span>   = Conf::get('email_ssl'<span>);//增加这一行
        </span><span>$mailer</span> = <span>new</span> Mailer(<span>$sender</span>, <span>$from</span>, <span>$protocol</span>, <span>$host</span>, <span>$port</span>, <span>$username</span>, <span>$password</span>, <span>$secure</span>);//同时传递参数
登入後複製

4. 调整后台email设置界面,增加相关设置项

后台模板:setting.email_setting.html 增加一个配置项

<span><</span><span>tr</span><span>></span>
                <span><</span><span>th </span><span>class</span><span>="paddingT15"</span><span>></span><span>
                    邮件服务器加密方式:</span><span></</span><span>th</span><span>></span>
                <span><</span><span>td </span><span>class</span><span>="paddingT15 wordSpacing5"</span><span>></span><span>
                    {html_radios name="email_ssl" options=$email_ssl checked=$setting.email_ssl}
                    </span><span><</span><span>label </span><span>class</span><span>="field_notice"</span><span>></span>此功能要求您的php必须支持OpenSSL模块, 如果您要使用此功能,请联系您的空间商确认支持此模块<span></</span><span>label</span><span>></span>
                <span></</span><span>td</span><span>></span>
            <span></</span><span>tr</span><span>></span>
登入後複製

同时,修改邮件测试的参数传递

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

然后还需要修改setting.app.php

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

            </span><span>$this</span>->show_message('edit_email_setting_successed'<span>);
        }
    }</span>
登入後複製

以及测试邮件方法。

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

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

 

tls方式没有测试过。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/771648.htmlTechArticle首先,主要是ecmall使用的phpmailer版本太低,不支持加密连接。 然后,得对相应代码做一定调整。 1. 覆盖phpmailer 请从附件进行下载: http:...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板