Home > Backend Development > PHP Tutorial > Detailed explanation of the configuration method of ECMall supporting SSL connection to the mail server_PHP tutorial

Detailed explanation of the configuration method of ECMall supporting SSL connection to the mail server_PHP tutorial

WBOY
Release: 2016-07-13 10:29:31
Original
1139 people have browsed it

First of all, the main reason is that the phpmailer version used by ecmall is too low and does not support encrypted connections.

Then, you have to make certain adjustments to the corresponding code.

1. Cover phpmailer

Please download from the attachment:

Copy the code The code is as follows:

http://cywl. jb51.net:81/201405/yuanma/ecmall_phpmailer_lib(jb51.net).zip

2. Modify lib

Involves two libs: mail.lib.php, mail_quequ.lib.php

In the constructors of these two classes, add a parameter to pass. Such as Mailer

Copy code The code is as follows:

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

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

The same applies to MailQueue.

3. Encapsulate calling functions

global.lib.php is about 300 lines

Add a line in function &get_mailer():

Copy code The code is as follows:

$secure = Conf::get('email_ssl');//Add this line
$mailer = new Mailer($sender, $from, $protocol, $host, $port, $username, $password, $secure);//Pass parameters at the same time

4. Adjust the background email setting interface and add related setting items

Backend template: setting.email_setting.html Add a configuration item

Copy code The code is as follows:


  Mail Server encryption method:
                                                                                                                                         class="field_notice">This function requires that your php must support the OpenSSL module. If you want to use this function, please contact your space provider to confirm that it supports this module




At the same time, modify the parameter delivery of the email test

Copy code The code is as follows:



Then you also need to modify setting.app.php

Copy code The code is as follows:

/**
* EMAIL Settings
*
* @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方式没有测试过。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/771874.htmlTechArticle首先,主要是ecmall使用的phpmailer版本太低,不支持加密连接。 然后,得对相应代码做一定调整。 1. 覆盖phpmailer 请从附件进行下载: 复制代...
Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template