@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
return array(
|
||||
'name' => '邮件短信',
|
||||
'version' => '1.2',
|
||||
'desc' => '邮件短信',
|
||||
'url' => 'http://www.thinksaas.cn',
|
||||
'email' => 'thinksaas@qq.com',
|
||||
'author' => '邱君',
|
||||
'author_url' => 'http://www.thinksaas.cn',
|
||||
'isoption' => '1',
|
||||
'isinstall' => '1',
|
||||
'issql' => '1',
|
||||
'issystem' => '1',
|
||||
'isappnav' => '0',
|
||||
'ismy'=>'0',
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
|
||||
//管理入口
|
||||
|
||||
if(is_file('app/'.$app.'/action/admin/'.$mg.'.php')){
|
||||
include_once 'app/'.$app.'/action/admin/'.$mg.'.php';
|
||||
}else{
|
||||
qiMsg('sorry:no index!');
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
|
||||
switch($ts){
|
||||
//APP配置选项
|
||||
case "options":
|
||||
$arrData = array(
|
||||
'appname' => tsTrim($_POST['appname']),
|
||||
'appdesc' => tsTrim($_POST['appdesc']),
|
||||
'isenable' => tsTrim($_POST['isenable']),
|
||||
'mailhost' => tsTrim($_POST['mailhost']),
|
||||
'ssl' => tsIntval($_POST['ssl']),
|
||||
'mailport' => tsTrim($_POST['mailport']),
|
||||
'mailuser' => tsTrim($_POST['mailuser']),
|
||||
'mailpwd' => tsTrim($_POST['mailpwd']),
|
||||
);
|
||||
|
||||
//先清空数据
|
||||
$db->query("TRUNCATE TABLE `".dbprefix."mail_options`");
|
||||
|
||||
foreach($arrData as $key=>$item){
|
||||
|
||||
$optionname = $key;
|
||||
$optionvalue = $item;
|
||||
|
||||
$new['mail']->create('mail_options',array(
|
||||
|
||||
'optionname'=>$optionname,
|
||||
'optionvalue'=>$optionvalue,
|
||||
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
//更新缓存
|
||||
$arrOptions = $new['mail']->findAll('mail_options',null,null,'optionname,optionvalue');
|
||||
foreach($arrOptions as $item){
|
||||
$arrOption[$item['optionname']] = $item['optionvalue'];
|
||||
}
|
||||
|
||||
fileWrite('mail_options.php','data',$arrOption);
|
||||
$tsMySqlCache->set('mail_options',$arrOption);
|
||||
|
||||
qiMsg("邮件配置更新成功,并重置了缓存文件^_^");
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "sms":
|
||||
|
||||
$arrData = array(
|
||||
'sms_server' => tsTrim($_POST['sms_server']),
|
||||
'sms_appid' => tsTrim($_POST['sms_appid']),
|
||||
'sms_appkey' => tsTrim($_POST['sms_appkey']),
|
||||
'sms_tpid' => tsTrim($_POST['sms_tpid']),
|
||||
'sms_sign' => tsTrim($_POST['sms_sign']),
|
||||
);
|
||||
|
||||
//更新缓存
|
||||
fileWrite('sms_options.php','data',$arrData);
|
||||
$GLOBALS['tsMySqlCache']->set('sms_options',$arrData);
|
||||
|
||||
qiMsg("短信配置更新成功,并重置了缓存文件^_^");
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
|
||||
switch($ts){
|
||||
|
||||
case "":
|
||||
|
||||
$arrOptions = $db->fetch_all_assoc("select * from ".dbprefix."mail_options");
|
||||
|
||||
foreach($arrOptions as $item){
|
||||
$strOption[$item['optionname']] = $item['optionvalue'];
|
||||
}
|
||||
|
||||
include template("admin/options");
|
||||
|
||||
break;
|
||||
|
||||
//短信配置
|
||||
case "sms":
|
||||
|
||||
$strOption = fileRead('data/sms_options.php');
|
||||
if($strOption==''){
|
||||
$strOption = $GLOBALS['tsMySqlCache']->get('sms_options');
|
||||
}
|
||||
|
||||
|
||||
include template("admin/options_sms");
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
use Qcloud\Sms\SmsSingleSender;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
|
||||
class mail extends tsApp{
|
||||
|
||||
//构造函数
|
||||
public function __construct($db){
|
||||
$tsAppDb = array();
|
||||
include 'app/mail/config.php';
|
||||
//判断APP是否采用独立数据库
|
||||
if($tsAppDb){
|
||||
$db = new MySql($tsAppDb);
|
||||
}
|
||||
|
||||
parent::__construct($db);
|
||||
}
|
||||
|
||||
//发送邮件
|
||||
function postMail($sendmail,$subject,$content){
|
||||
|
||||
global $TS_SITE,$tsMySqlCache;
|
||||
|
||||
$options = fileRead('data/mail_options.php');
|
||||
if($options==''){
|
||||
$options = $tsMySqlCache->get('mail_options');
|
||||
}
|
||||
|
||||
|
||||
|
||||
$mail = new PHPMailer(true); // Passing `true` enables exceptions
|
||||
try {
|
||||
//Server settings
|
||||
$mail->SMTPDebug = 0; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = $options['mailhost']; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = $options['mailuser']; // SMTP username
|
||||
$mail->Password = $options['mailpwd']; // SMTP password
|
||||
|
||||
|
||||
if($options['ssl']){
|
||||
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
||||
}
|
||||
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
|
||||
$mail->Port = $options['mailport']; // TCP port to connect to
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($options['mailuser'], $TS_SITE['site_title']);
|
||||
$mail->addAddress($sendmail, ''); // Add a recipient
|
||||
//$mail->addAddress($sendmail); // Name is optional
|
||||
$mail->addReplyTo($options['mailuser'], $TS_SITE['site_title']);
|
||||
|
||||
/*
|
||||
$mail->addCC('cc@example.com');
|
||||
$mail->addBCC('bcc@example.com');
|
||||
*/
|
||||
|
||||
//Attachments
|
||||
/*
|
||||
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
|
||||
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
||||
*/
|
||||
|
||||
//Content
|
||||
$mail->isHTML(true); // Set email format to HTML
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $content;
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
|
||||
$mail->send();
|
||||
//echo 'Message has been sent';
|
||||
|
||||
return 1;
|
||||
|
||||
} catch (Exception $e) {
|
||||
//echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//date_default_timezone_set('Asia/Shanghai');
|
||||
|
||||
/*
|
||||
require_once 'PHPMailer/PHPMailerAutoload.php';
|
||||
$mail = new PHPMailer();
|
||||
|
||||
//邮件配置
|
||||
$mail->CharSet = "UTF-8";
|
||||
$mail->IsSMTP();
|
||||
//Enable SMTP debugging
|
||||
// 0 = off (for production use)
|
||||
// 1 = client messages
|
||||
// 2 = client and server messages
|
||||
$mail->SMTPDebug = 0;
|
||||
|
||||
$mail->Debugoutput = 'html';
|
||||
|
||||
if($options['ssl']){
|
||||
$mail->SMTPSecure = 'ssl';
|
||||
}
|
||||
$mail->SMTPAuth = true;
|
||||
|
||||
$mail->Host = $options['mailhost'];
|
||||
$mail->Port = $options['mailport'];
|
||||
$mail->Username = $options['mailuser'];
|
||||
$mail->Password = $options['mailpwd'];
|
||||
|
||||
//POST过来的信息
|
||||
$frommail = $options['mailuser'];
|
||||
$fromname = $TS_SITE['site_title'];
|
||||
$replymail = $options['mailuser'];
|
||||
$replyname = $TS_SITE['site_title'];
|
||||
$sendname = '';
|
||||
|
||||
if(empty($frommail) || empty($subject) || empty($content) || empty($sendmail)){
|
||||
return '0';
|
||||
}else{
|
||||
|
||||
//邮件发送
|
||||
$mail->SetFrom($frommail, $fromname);
|
||||
$mail->AddReplyTo($replymail,$replyname);
|
||||
$mail->Subject = $subject;
|
||||
$mail->AltBody = "要查看邮件,请使用HTML兼容的电子邮件阅读器!";
|
||||
//$mail->MsgHTML(eregi_replace("[\]",'',$content));
|
||||
$mail->MsgHTML(strtr($content,'[\]',''));
|
||||
$mail->AddAddress($sendmail, $sendname);
|
||||
$mail->send();
|
||||
|
||||
return '1';
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
function sendSms($phone,$text,$tpid=0,$type=86){
|
||||
|
||||
$strOption = fileRead('data/sms_options.php');
|
||||
if($strOption==''){
|
||||
$strOption = $GLOBALS['tsMySqlCache']->get('sms_options');
|
||||
}
|
||||
|
||||
$sms_server = $strOption['sms_server'];
|
||||
|
||||
// 短信应用SDK AppID
|
||||
$appid = $strOption['sms_appid']; // 1400开头
|
||||
// 短信应用SDK AppKey
|
||||
$appkey = $strOption['sms_appkey'];
|
||||
// 短信模板ID,需要在短信应用中申请
|
||||
$templateId = $strOption['sms_tpid']; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
|
||||
if($tpid!=0){
|
||||
$templateId = $tpid;
|
||||
}
|
||||
// 签名
|
||||
$smsSign = $strOption['sms_sign']; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名,签名参数使用的是`签名内容`,而不是`签名ID`
|
||||
|
||||
#腾讯云发送短信
|
||||
if($sms_server=='qcloud'){
|
||||
// 指定模板ID单发短信
|
||||
try {
|
||||
$ssender = new SmsSingleSender($appid, $appkey);
|
||||
$params = ["$text"];
|
||||
$result = $ssender->sendWithParam("$type", $phone, $templateId,
|
||||
$params, $smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
|
||||
#$rsp = json_decode($result);
|
||||
//echo $result;
|
||||
} catch(\Exception $e) {
|
||||
//echo var_dump($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#阿里云发送短信
|
||||
if($sms_server=='aliyun'){
|
||||
AlibabaCloud::accessKeyClient($appid, $appkey)
|
||||
->regionId('cn-hangzhou') // replace regionId as you need
|
||||
->asGlobalClient();
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::rpcRequest()
|
||||
->product('Dysmsapi')
|
||||
// ->scheme('https') // https | http
|
||||
->version('2017-05-25')
|
||||
->action('SendSms')
|
||||
->method('POST')
|
||||
->options([
|
||||
'query' => [
|
||||
'RegionId' => 'cn-hangzhou',
|
||||
'PhoneNumbers' => $phone,
|
||||
'SignName' => $smsSign,
|
||||
'TemplateCode' => $templateId,
|
||||
'TemplateParam' => '{"code":"'.$text.'"}',
|
||||
],
|
||||
])
|
||||
->request();
|
||||
//print_r($result->toArray());
|
||||
} catch (ClientException $e) {
|
||||
//echo $e->getErrorMessage() . PHP_EOL;
|
||||
} catch (ServerException $e) {
|
||||
//echo $e->getErrorMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//析构函数
|
||||
public function __destruct(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
defined('IN_TS') or die('Access Denied.');
|
||||
|
||||
$TS_APP['appname'] = '邮件短信';
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
<div class="tabnav">
|
||||
|
||||
<h6>Email短信管理</h6>
|
||||
|
||||
<ul>
|
||||
<li {if $mg=='options' && $ts==''}class="select"{/if}><a href="{SITE_URL}index.php?app=mail&ac=admin&mg=options">Email配置</a></li>
|
||||
<li {if $mg=='options' && $ts=='sms'}class="select"{/if}><a href="{SITE_URL}index.php?app=mail&ac=admin&mg=options&ts=sms">短信配置</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div style="height: 100px;"></div>
|
||||
@@ -0,0 +1,43 @@
|
||||
{php include pubTemplate("header_admin")}
|
||||
|
||||
<div class="midder">
|
||||
|
||||
{php include template("admin/menu");}
|
||||
|
||||
<form method="POST" action="{SITE_URL}index.php?app=mail&ac=admin&mg=do&ts=options">
|
||||
|
||||
|
||||
|
||||
<table class="table table-hover">
|
||||
|
||||
<tr><td width="150">邮箱Host :</td><td><input name="mailhost" value="{$strOption[mailhost]}" /> (例如:smtp.exmail.qq.com)</td></tr>
|
||||
|
||||
<tr><td>使用ssl/tls:</td><td><input type="radio" name="ssl" value="0" {if $strOption['ssl']==0}checked{/if} />不使用 <input type="radio" name="ssl" value="1" {if $strOption['ssl']==1}checked{/if} /> 使用(使用SSL需要空间开启php_openssl扩展)</td></tr>
|
||||
|
||||
<tr><td>邮箱端口 :</td><td><input name="mailport" value="{$strOption[mailport]}" /> (例如:默认为25,ssl为465,tls为587)</td></tr>
|
||||
<tr><td>邮箱用户 :</td><td><input name="mailuser" value="{$strOption[mailuser]}" /> (例如:user@qq.com)</td></tr>
|
||||
<tr><td>邮箱密码 :</td><td><input type="password" name="mailpwd" value="" /> (例如:123456)</td></tr>
|
||||
|
||||
<tr><td></td><td>
|
||||
|
||||
<p>建议使用QQ企业邮箱 <a target="_blank" href="https://exmail.qq.com/">去申请</a></p>
|
||||
|
||||
<p>
|
||||
不懂怎么配置? <a target="_blank" href="https://www.thinksaas.cn/article/show/48/">ThinkSAAS邮件配置教程</a>
|
||||
</p>
|
||||
|
||||
|
||||
</td></tr>
|
||||
|
||||
|
||||
<tr><td width="150"></td><td><input class="btn btn-primary" type="submit" value="提 交" /> </td></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{php include pubTemplate("footer_admin")}
|
||||
@@ -0,0 +1,55 @@
|
||||
{php include pubTemplate("header_admin")}
|
||||
|
||||
<div class="midder">
|
||||
|
||||
{php include template("admin/menu");}
|
||||
|
||||
<form method="POST" action="{SITE_URL}index.php?app=mail&ac=admin&mg=do&ts=options&ts=sms">
|
||||
|
||||
|
||||
|
||||
<table class="table table-hover">
|
||||
<tr><td width="150">短信平台:</td><td>
|
||||
|
||||
|
||||
<input type="radio" name="sms_server" value="aliyun" {if $strOption['sms_server']=='aliyun'}checked{/if}>阿里云
|
||||
|
||||
<input type="radio" name="sms_server" value="qcloud" {if $strOption['sms_server']=='qcloud'}checked{/if}>腾讯云
|
||||
|
||||
|
||||
</td></tr>
|
||||
<tr><td>APPID:</td><td><input name="sms_appid" value="{$strOption['sms_appid']}" /></td></tr>
|
||||
<tr><td>APPKEY:</td><td><input name="sms_appkey" value="{$strOption['sms_appkey']}" /></td></tr>
|
||||
<tr><td>短信模板ID:</td><td><input name="sms_tpid" value="{$strOption['sms_tpid']}" /></td></tr>
|
||||
<tr><td>短信签名:</td><td><input name="sms_sign" value="{$strOption['sms_sign']}" /></td></tr>
|
||||
<tr><td></td><td>
|
||||
|
||||
|
||||
<div class="text-danger font-weight-bold">
|
||||
|
||||
<div>【推荐使用阿里云短信服务】</div>
|
||||
|
||||
<div class="mt-3">阿里云参数配置请点击 <a target="_blank" href="https://www.aliyun.com/product/sms?source=5176.11533457&userCode=t0dihnz2">阿里云短信服务</a> 获取 </div>
|
||||
<div class="mt-3">腾讯云参数配置请点击 <a target="_blank" href="https://www.qcloud.com/">腾讯云</a> 获取 </div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</td></tr>
|
||||
|
||||
|
||||
<tr><td width="150"></td><td><input class="btn btn-primary" type="submit" value="提 交" /> </td></tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{php include pubTemplate("footer_admin")}
|
||||
Reference in New Issue
Block a user