<?php $this->display(tpl('head'));?>
<style>
	.layui-form{
		padding-right: 40px;
	}
	.layui-row{
		margin-bottom: 10px;
	}
</style>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>邮箱设置</legend>
</fieldset>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="javascript::" lay-filter="testemail" lay-submit>发送测试邮件</a>
</div>
<form id="SETForm" class="layui-form" method="post">
	<div class="layui-form-item">
		<label class="layui-form-label">STMP服务器</label>
		<div class="layui-input-block">
			<input name="web[stmp_server]" value="<?php echo $setting['stmp_server'] ?>" class="layui-input" type="text">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">STMP端口号</label>
		<div class="layui-input-block">
			<input name="web[stmp_port]" value="<?php echo $setting['stmp_port'] ?>" class="layui-input" type="text">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">邮箱帐号</label>
		<div class="layui-input-block">
			<input name="web[stmp_username]"  value="<?php echo $setting['stmp_username'] ?>" class="layui-input" type="text">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">邮箱密码</label>
		<div class="layui-input-block">
			<input name="web[stmp_password]"  value="<?php echo $setting['stmp_password'] ?>" class="layui-input" type="password">
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-input-block my_button">
			<input type="hidden" name="step" id="step" value="post" />
			<button class="layui-btn">立即提交</button>
		</div>
	</div>
</form>

<form id="emailpost" class="layui-form" method="post" style="display: none;">
	<div class="layui-form-item" style="margin-top: 10px;">
		<label class="layui-form-label">收件人</label>
		<div class="layui-input-block">
			<input name="email"  class="layui-input" type="email">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">标题</label>
		<div class="layui-input-block">
			<input name="title"  class="layui-input" type="text">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">邮件内容</label>
		<div class="layui-input-block">
			<textarea class="layui-textarea" name="content"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block my_button">
			<input type="hidden" name="step" value="test_post_email" />
			<button class="layui-btn" lay-filter="testpostemail" lay-submit>确认发送</button>
		</div>
	</div>
</form>
<script type="text/javascript">
	layui.use(['form', 'layedit', 'laydate'], function() {
		var form = layui.form,
			layer = layui.layer,
			layedit = layui.layedit,
			laydate = layui.laydate;
			
			
		var testemail=	form.on('submit(testemail)', function(data){
			  	layer.open({
			  		title:'测试邮件系统',
			  		area:'50%',
				  	type: 1,
				  	content: $('#emailpost') 
				});
			});
			form.on('submit(testpostemail)', function(data){
				var jsons={json:true};
				c = $.extend({}, data.field,jsons);
				$.ajax({
					url:"/admin/setting/stmp/",
					type: 'POST',
					data:c,
					dataType: 'html',
					success: function(res){
						layer.msg(res);
					}	
				});
			  	return false;
			});
	});
</script>
<?php $this->display(tpl('foot')); 
