Home php教程 php手册 ECMall如何支持SSL连接邮件服务器的配置

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

Jun 13, 2016 am 09:35 AM
3 php python

首先,主要是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>....
Copy after login

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>);//同时传递参数
Copy after login

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>
Copy after login

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

<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>
Copy after login

然后还需要修改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>
Copy after login

以及测试邮件方法。

<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>
Copy after login

 

tls方式没有测试过。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python vs. JavaScript: Development Environments and Tools Python vs. JavaScript: Development Environments and Tools Apr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Golang vs. Python: The Pros and Cons Golang vs. Python: The Pros and Cons Apr 21, 2025 am 12:17 AM

Golangisidealforbuildingscalablesystemsduetoitsefficiencyandconcurrency,whilePythonexcelsinquickscriptinganddataanalysisduetoitssimplicityandvastecosystem.Golang'sdesignencouragesclean,readablecodeanditsgoroutinesenableefficientconcurrentoperations,t

Python vs. C  : Understanding the Key Differences Python vs. C : Understanding the Key Differences Apr 21, 2025 am 12:18 AM

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Laravel vs. Python (with Frameworks): A Comparative Analysis Laravel vs. Python (with Frameworks): A Comparative Analysis Apr 21, 2025 am 12:15 AM

Laravel is suitable for projects that teams are familiar with PHP and require rich features, while Python frameworks depend on project requirements. 1.Laravel provides elegant syntax and rich features, suitable for projects that require rapid development and flexibility. 2. Django is suitable for complex applications because of its "battery inclusion" concept. 3.Flask is suitable for fast prototypes and small projects, providing great flexibility.

See all articles