diff --git a/app/admin/controller/Api.php b/app/admin/controller/Api.php
index 273c558..da74548 100644
--- a/app/admin/controller/Api.php
+++ b/app/admin/controller/Api.php
@@ -202,25 +202,26 @@ class Api extends BaseController
// 测试邮件发送
public function email_test(){
- $sender = Request::param('email');
+ $sender = get_params('email');
//检查是否邮箱格式
if (!is_email($sender)) {
- return json(['error' => 1, 'msg' => '测试邮箱码格式有误']);
+ return to_assign(0, '测试邮箱码格式有误');
}
- $data = \app\common\model\Config::where('inc_type','smtp')
- ->select();
- $config = convert_arr_kv($data,'name','value');
- $content = $config['test_eamil_info'];
+ $email_config = \think\facade\Db::name('config')
+ ->where('name', 'email')
+ ->find();
+ $config = unserialize($email_config['content']);
+ $content = $config['template'];
//所有项目必须填写
- if (empty($config['smtp_server']) || empty($config['smtp_port']) || empty($config['smtp_user']) || empty($config['smtp_pwd'])) {
- return json(['error' => 1, 'msg' => '请完善邮件配置信息!']);
+ if (empty($config['smtp']) || empty($config['smtp_port']) || empty($config['smtp_user']) || empty($config['smtp_pwd'])) {
+ return to_assign(0, '请完善邮件配置信息!');
}
$send = send_email($sender, '测试邮件',$content);
if ($send) {
- return ['error' => 0, 'msg' => '邮件发送成功!'];
+ return to_assign(1, '邮件发送成功!');
} else {
- return ['error' => 1, 'msg' => '邮件发送失败!'];
+ return to_assign(0, '邮件发送失败!');
}
}
diff --git a/app/admin/view/conf/email.html b/app/admin/view/conf/email.html
index 802cfc8..fb6f539 100644
--- a/app/admin/view/conf/email.html
+++ b/app/admin/view/conf/email.html
@@ -18,8 +18,8 @@
协议端口号*
|
-
+
如:QQ邮箱的ssl协议方式端口号是465/587,163邮箱的ssl协议方式端口号是465/994
|
@@ -27,8 +27,8 @@
邮箱账户*
|
-
+
如:gougucms@qq.com
|
@@ -36,8 +36,8 @@
邮箱密码*
|
-
+
不一定是登录密码,如QQ邮箱的是第三方授权登录码,要自己去开启,在邮箱的设置->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
|
@@ -115,7 +115,7 @@
return false;
}
$.ajax({
- url: "/admin/api/emailto",
+ url: "/admin/api/email_test",
data: { email: value },
type: "post",
beforeSend: function () {
diff --git a/app/common.php b/app/common.php
index 87d324f..4d121cd 100644
--- a/app/common.php
+++ b/app/common.php
@@ -276,24 +276,24 @@ function isMobile()
function send_email($to, $subject = '', $content = '')
{
$mail = new PHPMailer\PHPMailer\PHPMailer();
- $arr = \think\facade\Db::name('config')
- ->where('inc_type', 'smtp')
- ->select();
- $config = convert_arr_kv($arr, 'name', 'value');
+ $email_config = \think\facade\Db::name('config')
+ ->where('name', 'email')
+ ->find();
+ $config = unserialize($email_config['content']);
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
$mail->isSMTP();
$mail->SMTPDebug = 0;
+
//调试输出格式
//$mail->Debugoutput = 'html';
//smtp服务器
- $mail->Host = $config['smtp_server'];
+ $mail->Host = $config['smtp'];
//端口 - likely to be 25, 465 or 587
$mail->Port = $config['smtp_port'];
-
- if ($mail->Port == '465') {
- $mail->SMTPSecure = 'ssl';
- }// 使用安全协议
+ if($mail->Port == '465'){
+ $mail->SMTPSecure = 'ssl';// 使用安全协议
+ }
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//发送邮箱
@@ -301,7 +301,7 @@ function send_email($to, $subject = '', $content = '')
//密码
$mail->Password = $config['smtp_pwd'];
//Set who the message is to be sent from
- $mail->setFrom($config['smtp_user'], $config['email_id']);
+ $mail->setFrom($config['email'], $config['from']);
//回复地址
//$mail->addReplyTo('replyto@example.com', 'First Last');
//接收邮件方
@@ -318,7 +318,14 @@ function send_email($to, $subject = '', $content = '')
$mail->Subject = $subject;
//HTML内容转换
$mail->msgHTML($content);
- return $mail->send();
+ $status = $mail->send();
+ if ($status) {
+ return true;
+ } else {
+ // echo "Mailer Error: ".$mail->ErrorInfo;// 输出错误信息
+ // die;
+ return false;
+ }
}
/**
diff --git a/composer.json b/composer.json
index e0b9e0c..a3b39e8 100644
--- a/composer.json
+++ b/composer.json
@@ -25,7 +25,8 @@
"topthink/think-orm": "^2.0",
"topthink/think-multi-app": "^1.0",
"topthink/think-view": "^1.0",
- "topthink/think-captcha": "^3.0"
+ "topthink/think-captcha": "^3.0",
+ "phpmailer/phpmailer": "^6.3"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
diff --git a/composer.lock b/composer.lock
index 7d678d0..181b1e5 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "e042aa44f0428c2c539731651ec0e8bd",
+ "content-hash": "a370397ef9edcd1604ce0397d6c4e36e",
"packages": [
{
"name": "league/flysystem",
@@ -225,6 +225,88 @@
],
"time": "2020-10-18T11:50:25+00:00"
},
+ {
+ "name": "phpmailer/phpmailer",
+ "version": "v6.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/PHPMailer/PHPMailer.git",
+ "reference": "4a08cf4cdd2c38d12ee2b9fa69e5d235f37a6dcb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/4a08cf4cdd2c38d12ee2b9fa69e5d235f37a6dcb",
+ "reference": "4a08cf4cdd2c38d12ee2b9fa69e5d235f37a6dcb",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "ext-ctype": "*",
+ "ext-filter": "*",
+ "ext-hash": "*",
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
+ "doctrine/annotations": "^1.2",
+ "phpcompatibility/php-compatibility": "^9.3.5",
+ "roave/security-advisories": "dev-latest",
+ "squizlabs/php_codesniffer": "^3.5.6",
+ "yoast/phpunit-polyfills": "^0.2.0"
+ },
+ "suggest": {
+ "ext-mbstring": "Needed to send email in multibyte encoding charset",
+ "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
+ "league/oauth2-google": "Needed for Google XOAUTH2 authentication",
+ "psr/log": "For optional PSR-3 debug logging",
+ "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication",
+ "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "PHPMailer\\PHPMailer\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "LGPL-2.1-only"
+ ],
+ "authors": [
+ {
+ "name": "Marcus Bointon",
+ "email": "phpmailer@synchromedia.co.uk"
+ },
+ {
+ "name": "Jim Jagielski",
+ "email": "jimjag@gmail.com"
+ },
+ {
+ "name": "Andy Prevost",
+ "email": "codeworxtech@users.sourceforge.net"
+ },
+ {
+ "name": "Brent R. Matzelle"
+ }
+ ],
+ "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
+ "support": {
+ "issues": "https://github.com/PHPMailer/PHPMailer/issues",
+ "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.3.0"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/Synchro",
+ "type": "github"
+ }
+ ],
+ "time": "2021-02-19T15:28:08+00:00"
+ },
{
"name": "psr/cache",
"version": "1.0.1",