How does ECMall support the configuration of SSL connection to the mail server?

Source: Internet
Author: User
Tags ssl connection

First, the phpmailer version used by ecmall is too low and does not support encrypted connections.

Then, make some adjustments to the corresponding code.

1. Overwrite phpmailer

Download the attachment:

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

2. Modify lib

Two lib involved: mail. lib. php and mail_quequ.lib.php

Add a parameter to the constructor of these two classes. For example, Mailer

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 is true for MailQueue.

 

3. encapsulate the call Function

About 300 rows in global. lib. php

Add a row to function & get_mailer:

$ Secure = Conf: get ('email _ ssl '); // Add this line $ mailer = new Mailer ($ sender, $ from, $ protocol, $ host, $ port, $ username, $ password, $ secure); // simultaneously passing Parameters

 

4. Adjust the background email settings page and add related settings

Background template: setting.email_setting.html adds a configuration item

<Tr> <th class = "paddingT15"> email server encryption method: </th> <td class = "paddingT15 wordSpacing5"> {html_radios name = "email_ssl" options = $ email_ssl checked = $ setting. email_ssl} <label class = "field_notice"> This function requires your php to support the OpenSSL module. If you want to use this function, contact your space provider to confirm support for this module </label> </td> </tr>

 

At the same time, modify the mail test parameter transmission

<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 row $. 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 also need to modify setting. app. php

/*** EMAIL settings ** @ author Hyber * @ return void */function email_setting () {$ model_setting = & af ('settings '); $ setting = $ model_setting-> getAll (); // load the data set by the system if (! IS_POST) {$ this-> assign ('setting', $ setting); $ this-> assign ('mail _ type', array (MAIL_PROTOCOL_SMTP => Lang :: get ('smtp '), MAIL_PROTOCOL_LOCAL => Lang: get ('email '),));
// Add $ this-> assign ('email _ ssl ', array (0 => Lang: get ('no'), 1 => 'ssl ', 2 => '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']; // Add $ 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 the mail method.

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 ']; // Add $ 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 ); // Add $ 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.