作者 邓超

1

... ... @@ -3,6 +3,8 @@
namespace Controller;
use Model\emailSql;
/**
* 基础控制器,根据需求 可以不继承此类
* @author:dc
... ... @@ -12,7 +14,25 @@ namespace Controller;
*/
abstract class Base {
/**
* 当前登录的邮箱
* @var array[]
*/
protected $login_email;
/**
* 构造
* Home constructor.
*/
public function __construct()
{
// 获取 当前请求的 邮箱
$this->login_email = db()->first(emailSql::firstByToken(token()));
if(!$this->login_email){
app()->e('token_verify_notfound');
}
}
... ...
<?php
namespace Controller;
/**
* 文件夹管理
* @author:dc
* @time 2023/2/18 17:58
* Class Folder
* @package Controller
*/
class Folder extends Base {
/**
* 邮箱文件夹
* @author:dc
* @time 2023/2/18 10:58
*/
public function lists(){
// 查询
$folders = db()->all(
\Model\folderSql::all(
$this->login_email['id'],
'`id`,`folder`,`pid`'
)
);
// 转tree
$folders = list_to_tree($folders);
app()->_json($folders);
}
/**
* 创建 目录
* @author:dc
* @time 2023/2/18 17:56
*/
public function create(){
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace Controller;
use Lib\Mail\MailFun;
use Model\emailSql;
use Model\listsSql;
... ... @@ -11,27 +12,8 @@ use Model\listsSql;
* Class Home
* @package Controller
*/
class Home {
class Home extends Base {
/**
* 当前登录的邮箱
* @var array[]
*/
private $login_email;
/**
* 构造
* Home constructor.
*/
public function __construct()
{
// 获取 当前请求的 邮箱
$this->login_email = db()->first(emailSql::firstByToken(token()));
if(!$this->login_email){
app()->e('token_verify_notfound');
}
}
/**
* 邮件列表
... ... @@ -51,29 +33,21 @@ class Home {
}
/**
* 邮箱文件夹
* 发送邮件
* @author:dc
* @time 2023/2/18 10:58
* @time 2023/2/18 17:32
*/
public function folder(){
// 查询
$folders = db()->all(
\Model\folderSql::all(
$this->login_email['id'],
'`id`,`folder`,`pid`'
)
);
// 转tree
$folders = list_to_tree($folders);
app()->_json($folders);
}
public function send_mail(){
$ret = MailFun::sendEmail();
if($ret[0]===true) {
app()->_json(['messageId'=>$ret[1]]);
}else {
app()->e($ret[1]);
}
}
... ...
... ... @@ -121,6 +121,7 @@ class MailFun {
/**
* 发送邮件
* @param string $smtp smtp服务器地址
* @param string $username 发件人
* @param string $password 发件人密码
... ... @@ -131,17 +132,17 @@ class MailFun {
* @param array $files 文件 ['origin_name'=>'','path'=>'']
* @param false $receipt 是否回执
* @param int $priority 是否紧急 1紧急 3正常 5慢
* @return bool
* @return array
* @throws \PHPMailer\PHPMailer\Exception
* @author:dc
* @time 2022/11/11 14:26
* @time 2023/2/18 17:45
*/
public static function sendEmail(string $smtp,string $username,string $password,string $nickname,$to_email,string $subject,string $body,$files=[],$receipt=false,$priority=3){
public static function sendEmail(string $smtp,string $username,string $password,string $nickname,string|array $to_email,string $subject,string $body,$files=[],$receipt=false,$priority=3){
// 邮件对象
$mail = new PHPMailer(true);
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_CLIENT;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = $smtp; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
... ... @@ -193,10 +194,10 @@ class MailFun {
// 发送
if($mail->send()){
return true;
return [true,$mail->getLastMessageID()];
}
throw new \Exception($mail->ErrorInfo,500);
return [false,$mail->ErrorInfo];
}
... ...
... ... @@ -14,7 +14,7 @@ return [
* @param string imap imap服务器地址
* @param string smtp smtp服务器地址
*/
'login' => [\Controller\Login::class,'login'],
'login' => [\Controller\Login::class, 'login'],
/**
* 邮件列表
... ... @@ -22,13 +22,30 @@ return [
* @param string _token_ token登录凭证
* @param int page 当前页数
*/
'mail/list' => [\Controller\Home::class,'lists'],
'mail/list' => [\Controller\Home::class, 'lists'],
/**
* 邮件文件夹
* @see \Controller\Home::folder()
* @see \Controller\Folder::lists()
* @param string _token_ token登录凭证
*/
'mail/folder' => [\Controller\Home::class,'folder'],
'mail/folder' => [\Controller\Folder::class, 'lists'],
/**
* 邮件/创建文件夹
* @see \Controller\Folder::create()
* @param string _token_ token登录凭证
*/
'mail/folder/create' => [\Controller\Folder::class, 'create'],
/**
* 发送邮件
* @see \Controller\Home::send_mail()
* @param string _token_ token登录凭证
*/
'mail/send' => [\Controller\Home::class, 'send_mail'],
];
... ...