正在显示
5 个修改的文件
包含
129 行增加
和
50 行删除
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | namespace Controller; | 3 | namespace Controller; |
4 | 4 | ||
5 | 5 | ||
6 | +use Model\emailSql; | ||
7 | + | ||
6 | /** | 8 | /** |
7 | * 基础控制器,根据需求 可以不继承此类 | 9 | * 基础控制器,根据需求 可以不继承此类 |
8 | * @author:dc | 10 | * @author:dc |
@@ -12,7 +14,25 @@ namespace Controller; | @@ -12,7 +14,25 @@ namespace Controller; | ||
12 | */ | 14 | */ |
13 | abstract class Base { | 15 | abstract class Base { |
14 | 16 | ||
17 | + /** | ||
18 | + * 当前登录的邮箱 | ||
19 | + * @var array[] | ||
20 | + */ | ||
21 | + protected $login_email; | ||
15 | 22 | ||
23 | + /** | ||
24 | + * 构造 | ||
25 | + * Home constructor. | ||
26 | + */ | ||
27 | + public function __construct() | ||
28 | + { | ||
29 | + // 获取 当前请求的 邮箱 | ||
30 | + $this->login_email = db()->first(emailSql::firstByToken(token())); | ||
31 | + if(!$this->login_email){ | ||
32 | + app()->e('token_verify_notfound'); | ||
33 | + } | ||
34 | + | ||
35 | + } | ||
16 | 36 | ||
17 | 37 | ||
18 | 38 |
controller/Folder.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Controller; | ||
4 | + | ||
5 | + | ||
6 | +/** | ||
7 | + * 文件夹管理 | ||
8 | + * @author:dc | ||
9 | + * @time 2023/2/18 17:58 | ||
10 | + * Class Folder | ||
11 | + * @package Controller | ||
12 | + */ | ||
13 | +class Folder extends Base { | ||
14 | + | ||
15 | + | ||
16 | + /** | ||
17 | + * 邮箱文件夹 | ||
18 | + * @author:dc | ||
19 | + * @time 2023/2/18 10:58 | ||
20 | + */ | ||
21 | + public function lists(){ | ||
22 | + // 查询 | ||
23 | + $folders = db()->all( | ||
24 | + \Model\folderSql::all( | ||
25 | + $this->login_email['id'], | ||
26 | + '`id`,`folder`,`pid`' | ||
27 | + ) | ||
28 | + ); | ||
29 | + | ||
30 | + // 转tree | ||
31 | + $folders = list_to_tree($folders); | ||
32 | + | ||
33 | + app()->_json($folders); | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | ||
39 | + /** | ||
40 | + * 创建 目录 | ||
41 | + * @author:dc | ||
42 | + * @time 2023/2/18 17:56 | ||
43 | + */ | ||
44 | + public function create(){ | ||
45 | + | ||
46 | + } | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + | ||
53 | +} | ||
54 | + | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + | ||
64 | + | ||
65 | + | ||
66 | + | ||
67 | + |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace Controller; | 3 | namespace Controller; |
4 | 4 | ||
5 | +use Lib\Mail\MailFun; | ||
5 | use Model\emailSql; | 6 | use Model\emailSql; |
6 | use Model\listsSql; | 7 | use Model\listsSql; |
7 | 8 | ||
@@ -11,27 +12,8 @@ use Model\listsSql; | @@ -11,27 +12,8 @@ use Model\listsSql; | ||
11 | * Class Home | 12 | * Class Home |
12 | * @package Controller | 13 | * @package Controller |
13 | */ | 14 | */ |
14 | -class Home { | 15 | +class Home extends Base { |
15 | 16 | ||
16 | - /** | ||
17 | - * 当前登录的邮箱 | ||
18 | - * @var array[] | ||
19 | - */ | ||
20 | - private $login_email; | ||
21 | - | ||
22 | - /** | ||
23 | - * 构造 | ||
24 | - * Home constructor. | ||
25 | - */ | ||
26 | - public function __construct() | ||
27 | - { | ||
28 | - // 获取 当前请求的 邮箱 | ||
29 | - $this->login_email = db()->first(emailSql::firstByToken(token())); | ||
30 | - if(!$this->login_email){ | ||
31 | - app()->e('token_verify_notfound'); | ||
32 | - } | ||
33 | - | ||
34 | - } | ||
35 | 17 | ||
36 | /** | 18 | /** |
37 | * 邮件列表 | 19 | * 邮件列表 |
@@ -51,29 +33,21 @@ class Home { | @@ -51,29 +33,21 @@ class Home { | ||
51 | } | 33 | } |
52 | 34 | ||
53 | 35 | ||
36 | + | ||
54 | /** | 37 | /** |
55 | - * 邮箱文件夹 | 38 | + * 发送邮件 |
56 | * @author:dc | 39 | * @author:dc |
57 | - * @time 2023/2/18 10:58 | 40 | + * @time 2023/2/18 17:32 |
58 | */ | 41 | */ |
59 | - public function folder(){ | ||
60 | - // 查询 | ||
61 | - $folders = db()->all( | ||
62 | - \Model\folderSql::all( | ||
63 | - $this->login_email['id'], | ||
64 | - '`id`,`folder`,`pid`' | ||
65 | - ) | ||
66 | - ); | ||
67 | - | ||
68 | - // 转tree | ||
69 | - $folders = list_to_tree($folders); | ||
70 | - | ||
71 | - app()->_json($folders); | ||
72 | - } | ||
73 | - | ||
74 | - | ||
75 | - | 42 | + public function send_mail(){ |
43 | + $ret = MailFun::sendEmail(); | ||
76 | 44 | ||
45 | + if($ret[0]===true) { | ||
46 | + app()->_json(['messageId'=>$ret[1]]); | ||
47 | + }else { | ||
48 | + app()->e($ret[1]); | ||
49 | + } | ||
50 | + } | ||
77 | 51 | ||
78 | 52 | ||
79 | 53 |
@@ -121,6 +121,7 @@ class MailFun { | @@ -121,6 +121,7 @@ class MailFun { | ||
121 | 121 | ||
122 | 122 | ||
123 | /** | 123 | /** |
124 | + * 发送邮件 | ||
124 | * @param string $smtp smtp服务器地址 | 125 | * @param string $smtp smtp服务器地址 |
125 | * @param string $username 发件人 | 126 | * @param string $username 发件人 |
126 | * @param string $password 发件人密码 | 127 | * @param string $password 发件人密码 |
@@ -131,17 +132,17 @@ class MailFun { | @@ -131,17 +132,17 @@ class MailFun { | ||
131 | * @param array $files 文件 ['origin_name'=>'','path'=>''] | 132 | * @param array $files 文件 ['origin_name'=>'','path'=>''] |
132 | * @param false $receipt 是否回执 | 133 | * @param false $receipt 是否回执 |
133 | * @param int $priority 是否紧急 1紧急 3正常 5慢 | 134 | * @param int $priority 是否紧急 1紧急 3正常 5慢 |
134 | - * @return bool | 135 | + * @return array |
135 | * @throws \PHPMailer\PHPMailer\Exception | 136 | * @throws \PHPMailer\PHPMailer\Exception |
136 | * @author:dc | 137 | * @author:dc |
137 | - * @time 2022/11/11 14:26 | 138 | + * @time 2023/2/18 17:45 |
138 | */ | 139 | */ |
139 | - public static function sendEmail(string $smtp,string $username,string $password,string $nickname,$to_email,string $subject,string $body,$files=[],$receipt=false,$priority=3){ | 140 | + 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){ |
140 | 141 | ||
141 | // 邮件对象 | 142 | // 邮件对象 |
142 | - $mail = new PHPMailer(true); | 143 | + $mail = new PHPMailer(); |
143 | //Server settings | 144 | //Server settings |
144 | - $mail->SMTPDebug = SMTP::DEBUG_CLIENT;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output | 145 | + $mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output |
145 | $mail->isSMTP(); //Send using SMTP | 146 | $mail->isSMTP(); //Send using SMTP |
146 | $mail->Host = $smtp; //Set the SMTP server to send through | 147 | $mail->Host = $smtp; //Set the SMTP server to send through |
147 | $mail->SMTPAuth = true; //Enable SMTP authentication | 148 | $mail->SMTPAuth = true; //Enable SMTP authentication |
@@ -193,10 +194,10 @@ class MailFun { | @@ -193,10 +194,10 @@ class MailFun { | ||
193 | 194 | ||
194 | // 发送 | 195 | // 发送 |
195 | if($mail->send()){ | 196 | if($mail->send()){ |
196 | - return true; | 197 | + return [true,$mail->getLastMessageID()]; |
197 | } | 198 | } |
198 | 199 | ||
199 | - throw new \Exception($mail->ErrorInfo,500); | 200 | + return [false,$mail->ErrorInfo]; |
200 | 201 | ||
201 | } | 202 | } |
202 | 203 |
@@ -14,7 +14,7 @@ return [ | @@ -14,7 +14,7 @@ return [ | ||
14 | * @param string imap imap服务器地址 | 14 | * @param string imap imap服务器地址 |
15 | * @param string smtp smtp服务器地址 | 15 | * @param string smtp smtp服务器地址 |
16 | */ | 16 | */ |
17 | - 'login' => [\Controller\Login::class,'login'], | 17 | + 'login' => [\Controller\Login::class, 'login'], |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * 邮件列表 | 20 | * 邮件列表 |
@@ -22,13 +22,30 @@ return [ | @@ -22,13 +22,30 @@ return [ | ||
22 | * @param string _token_ token登录凭证 | 22 | * @param string _token_ token登录凭证 |
23 | * @param int page 当前页数 | 23 | * @param int page 当前页数 |
24 | */ | 24 | */ |
25 | - 'mail/list' => [\Controller\Home::class,'lists'], | 25 | + 'mail/list' => [\Controller\Home::class, 'lists'], |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * 邮件文件夹 | 28 | * 邮件文件夹 |
29 | - * @see \Controller\Home::folder() | 29 | + * @see \Controller\Folder::lists() |
30 | * @param string _token_ token登录凭证 | 30 | * @param string _token_ token登录凭证 |
31 | */ | 31 | */ |
32 | - 'mail/folder' => [\Controller\Home::class,'folder'], | 32 | + 'mail/folder' => [\Controller\Folder::class, 'lists'], |
33 | + | ||
34 | + /** | ||
35 | + * 邮件/创建文件夹 | ||
36 | + * @see \Controller\Folder::create() | ||
37 | + * @param string _token_ token登录凭证 | ||
38 | + */ | ||
39 | + 'mail/folder/create' => [\Controller\Folder::class, 'create'], | ||
40 | + | ||
41 | + /** | ||
42 | + * 发送邮件 | ||
43 | + * @see \Controller\Home::send_mail() | ||
44 | + * @param string _token_ token登录凭证 | ||
45 | + */ | ||
46 | + 'mail/send' => [\Controller\Home::class, 'send_mail'], | ||
33 | 47 | ||
34 | ]; | 48 | ]; |
49 | + | ||
50 | + | ||
51 | + |
-
请 注册 或 登录 后发表评论