ECMall Support SSL Connection Mail Server Configuration Details

  • 2021-06-28 11:24:14
  • OfStack

First, ecmall mainly uses a version of phpmailer that is too low to support encrypted connections.

Then, you have to make a certain adjustment to the corresponding code.

1. Overwrite phpmailer

Please download it from the attachment:


http://cywl.ofstack.com:81/201405/yuanma/ecmall_phpmailer_lib(ofstack.com).zip

2. Renovate lib

Two lib are involved: mail.lib.php, mail_quequ.lib.php

In the constructors of these two classes, add a parameter pass.For example, Mailer


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

The same is true in MailQueue.

3. Encapsulate calling functions

global.lib.php is about 300 lines

function & get_Add 1 line to mailer():


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

4. Adjust the background email setup interface to add related settings

Background template: setting.email_setting.html Add 1 Configuration Item


<tr>
    <th class="paddingT15"> Mail Server Encryption :</th>
    <td class="paddingT15 wordSpacing5">
       {html_radios name="email_ssl" options=$email_ssl checked=$setting.email_ssl}
        <label class="field_notice"> This feature requires your php Must support OpenSSL Modular ,  If you want to use this feature, please contact your space provider to confirm support for this module </label>
    </td>
</tr>

Also, modify parameter delivery for mail tests


<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();// Add this 1 That's ok 
    $.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>

You then need to modify setting.app.php


/**
     *    EMAIL  Set up 
     *
     *    @author    Hyber
     *    @return    void
     */
    function email_setting()
    {
        $model_setting = &af('settings');
        $setting = $model_setting->getAll(); // Loading System Settings Data 
        if (!IS_POST)
        {
            $this->assign('setting', $setting);
            $this->assign('mail_type', array(
                MAIL_PROTOCOL_SMTP  => Lang::get('smtp'),
                MAIL_PROTOCOL_LOCAL => Lang::get('email'),
            ));
 * // increase 
            $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'];// increase 
            $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');
        }
    }

And test mail methods.


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'];// increase 
            $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');
            /*  Use mailer class  */
            import('mailer.lib');
            $mailer = new Mailer($email_from, $email_addr, $email_type, $email_host, $email_port, $email_id, $email_pass, $email_ssl);// increase 
            $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');
        }
    }

The tls method has not been tested.


Related articles: