1 Star 0 Fork 0

Stefan阿钢/yu_sendmail

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sendmail.php 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
何秀钢 提交于 2021-07-02 15:23 . modified 邮件配置
<?php
/**
* Created by Stefan Ho.
* User: Stefan <[email protected]>
* Date: 2021-07-02 08:54
*/
define('TIME_ZONE', 'Asia/Shanghai');
define('DS', DIRECTORY_SEPARATOR);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
@set_time_limit(0);
define('ROOT_PATH', dirname(__FILE__) . DS);
date_default_timezone_set(TIME_ZONE);
define('TIMESTAMP', time());
require_once ROOT_PATH . './include/function.php';
if(function_exists('mysql_connect')) {
require ROOT_PATH . './include/db_mysql.php';
} else {
require ROOT_PATH . './include/db_mysqli.php';
}
$argv = array_value($_SERVER, 'argv');
$mod = $argv[1] ?? '';
$mod_array = ['index', 'test'];
$mod = !in_array($mod, $mod_array) ? 'index' : $mod;
/** db */
$_config = [];
$config_file = ROOT_PATH . './config.php';
if(!file_exists($config_file)) {
exit('config err');
} else {
include $config_file;
}
$dbhost = $_config['db'][1]['dbhost'];
$dbname = $_config['db'][1]['dbname'];
$dbpw = $_config['db'][1]['dbpw'];
$dbuser = $_config['db'][1]['dbuser'];
$dbcharset = $_config['db'][1]['dbcharset'];
$tablepre = $_config['db'][1]['tablepre'];
$db = new dbstuff();
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $dbcharset);
/**
* 主函数
*/
function run_index() {
global $db, $tablepre, $_config;
$mail_config = $_config['mail_server'];
$today = date('m-d', TIMESTAMP);
$user_list = $db->fetch_all("SELECT * FROM {$tablepre}user WHERE DATE_FORMAT(job_time, '%m-%d')='" . $today . "'");
if(empty($user_list)) {
echo 'No data' . PHP_EOL;
exit;
}
foreach($user_list as $item) {
$res = send_mail($mail_config, $item['email'], $mail_config['title'], $mail_config['content']);
pr('send ' . $item['email'], $res);
echo PHP_EOL;
}
}
/**
* 测试邮件
*/
function run_test() {
global $_config;
$mail_config = $_config['mail_server'];
$to = $mail_config['admin'];
if(!$to) {
echo 'No email' . PHP_EOL;
exit;
}
$mail_config['admin'] = '';
$res = send_mail($mail_config, $to, $mail_config['title'], $mail_config['content']);
pr($res);
}
$run = 'run_' . $mod;
$run();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bstdn/yu_sendmail.git
[email protected]:bstdn/yu_sendmail.git
bstdn
yu_sendmail
yu_sendmail
master

搜索帮助