ECMall支持SSL连接邮件服务器的配置方法详解

前端之家收集整理的这篇文章主要介绍了ECMall支持SSL连接邮件服务器的配置方法详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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


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


@H_404_0@1. 覆盖PHPmailer


@H_404_0@请从附件进行下载:<div class="codetitle"><a style="CURSOR: pointer" data="41239" class="copybut" id="copybut41239" onclick="doCopy('code41239')"> 代码如下:
<div class="codebody" id="code41239">
http://cywl.jb51.cc:81/201405/yuanma/ecmall_phpmailer_lib(jb51.cc).zip


@H_4040@2. 改造lib


@H
404_0@涉及到两个lib:mail.lib.PHP 、mail_quequ.lib.PHP


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


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="32953" class="copybut" id="copybut32953" onclick="doCopy('code32953')"> 代码如下:
<div class="codebody" id="code32953">
function __construct($from,$email,$protocol,$host = '',$port = '',$user = '',$pass = '',$SMTPSecure = false)//增加$SMTPSecure
{
$this->Mailer($from,$host,$port,$user,$pass,$SMTPSecure);
}


@H_4040@ function Mailer($from,$SMTPSecure = false)
....


@H
4040@MailQueue中同理。


@H
404_0@3. 封装调用函数


@H_404_0@global.lib.PHP 约300行


@H_404_0@function &get_mailer()中增加一行:


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="10927" class="copybut" id="copybut10927" onclick="doCopy('code10927')"> 代码如下:
<div class="codebody" id="code10927">
$secure = Conf::get('email_ssl');//增加这一行
$mailer = new Mailer($sender,$from,$username,$password,$secure);//同时传递参数


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


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


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="50448" class="copybut" id="copybut50448" onclick="doCopy('code50448')"> 代码如下:
<div class="codebody" id="code50448">
<tr>
<th class="paddingT15">邮件服务器加密方式:
<td class="paddingT15 wordSpacing5">
{html_radios name="email_ssl" options=$email_ssl checked=$setting.email_ssl}
<label class="field_notice">此功能要求您的PHP必须支持OpenSSL模块,如果您要使用此功能,请联系您的空间商确认支持此模块
</td>
</tr>


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


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="31885" class="copybut" id="copybut31885" onclick="doCopy('code31885')"> 代码如下:<div class="codebody" id="code31885">
<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();//增加这一行
$.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_sendfailure}');}
});
}


@H
404_0@然后还需要修改setting.app.PHP


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="14131" class="copybut" id="copybut14131" onclick="doCopy('code14131')"> 代码如下:<div class="codebody" id="code14131">
/*
EMAIL 设置

@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'];
$modelsetting->setAll($data);


@H
404_0@ $this->show_message('edit_email_settingsuccessed');
}
}


@H
404_0@以及测试邮件方法


@H_404_0@<div class="codetitle"><a style="CURSOR: pointer" data="40835" class="copybut" id="copybut40835" onclick="doCopy('code40835')"> 代码如下:<div class="codebody" id="code40835">
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('emailcontent');


@H
404_0@ / 使用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->showwarning('Hacking Attempt');
}
}


@H
404_0@tls方式没有测试过。

猜你在找的PHP相关文章