Skip to content

Commit bf78342

Browse files
committed
Frist push
1 parent 59e0cff commit bf78342

File tree

4 files changed

+578
-0
lines changed

4 files changed

+578
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# Umbrella
22
一个PHP的小程序,可以设置定时发送邮件提醒带伞
3+
4+
https://console.heweather.com/申请好KEY后
5+
6+
于config.php内填写合适内容即可享用本脚本

UmbrellaV2.PHP

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<meta http-equiv="content-type" content="text/html;charset=utf-8">
2+
<?php
3+
//带伞提醒 Ver.2
4+
require 'config.php';
5+
//对json格式的字符串进行编码
6+
$arr = json_decode($str,TRUE);
7+
//城市名
8+
$city = ($arr['HeWeather6']['0']['basic']['location']);
9+
$motd = "亦可赛艇!";
10+
foreach($arr['HeWeather6'][0]['daily_forecast']as $key => $val)
11+
{
12+
$data[] = "日期:" .$val['date'];
13+
$txt_d[] = "{$val['cond_txt_d']}";
14+
$txt_n[] = "{$val['cond_txt_n']}";
15+
$winds[] = "{$val['wind_dir']}";
16+
$tmps[] = "{$val['tmp_max']}~{$val['tmp_min']}";
17+
}
18+
if($txt_d[0] == $txt_n[0]){
19+
$weather0 = $txt_d[0];
20+
}else{
21+
$weather0 = $txt_d[0]."".$txt_n[0];
22+
};
23+
24+
if($txt_d[1] == $txt_n[1]){
25+
$weather1 = $txt_n[1];
26+
}else{
27+
$weather1 = $txt_d[1]."".$txt_n[1];
28+
};
29+
30+
if($txt_d[2] == $txt_n[2]){
31+
$weather2 = $txt_n[2];
32+
}else{
33+
$weather2 = $txt_d[2]."".$txt_n[2];
34+
};
35+
36+
if(strstr($weather0,"")){
37+
$need = "需要带伞";
38+
$today = "今天会下雨哦";
39+
}else{
40+
$need = "不需要带伞";
41+
$today = "今天是个好天气";
42+
}
43+
$weather0 = $weather0.",".$winds[0].",".$tmps[0];
44+
$weather1 = $weather1.",".$winds[1].",".$tmps[1];
45+
$weather2 = $weather2.",".$winds[2].",".$tmps[2];
46+
47+
48+
$mai = <<<LABELSS
49+
<style type="text/css">
50+
img {
51+
max-width: 100%;
52+
}
53+
body {
54+
-webkit-font-smoothing: antialiased;
55+
-webkit-text-size-adjust: none;
56+
width: 100% !important;
57+
58+
line-height: 1.6em;
59+
}
60+
body {
61+
background-color: #f6f6f6;
62+
}
63+
@media only screen and (max-width: 640px) {
64+
body {
65+
padding: 0 !important;
66+
}
67+
h1 {
68+
font-weight: 800 !important;
69+
margin: 20px 0 5px !important;
70+
}
71+
h2 {
72+
font-weight: 800 !important;
73+
margin: 20px 0 5px !important;
74+
}
75+
h3 {
76+
font-weight: 800 !important;
77+
margin: 20px 0 5px !important;
78+
}
79+
h4 {
80+
font-weight: 800 !important;
81+
margin: 20px 0 5px !important;
82+
}
83+
h1 {
84+
font-size: 22px !important;
85+
}
86+
h2 {
87+
font-size: 18px !important;
88+
}
89+
h3 {
90+
font-size: 16px !important;
91+
}
92+
.container {
93+
padding: 0 !important;
94+
width: 100% !important;
95+
}
96+
.content {
97+
padding: 0 !important;
98+
}
99+
.content-wrap {
100+
padding: 10px !important;
101+
}
102+
.invoice {
103+
width: 100% !important;
104+
}
105+
}
106+
</style>
107+
108+
<table class="body-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
109+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
110+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
111+
<td class="container" width="600" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;" valign="top">
112+
<div class="content" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;">
113+
<table class="main" width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" bgcolor="#fff">
114+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
115+
<td class="content-wrap aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 20px;" align="center" valign="top">
116+
<table width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
117+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
118+
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
119+
<h1 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 32px; color: #000; line-height: 1.2em; font-weight: 500; text-align: center; margin: 40px 0 0;" align="center"></h1>
120+
</td>
121+
</tr>
122+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
123+
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
124+
<h2 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 24px; color: #000; line-height: 1.2em; font-weight: 400; text-align: center; margin: 40px 0 0;" align="center">{$today}</h2>
125+
<h4 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 24px; color: #000; line-height: 1.2em; font-weight: 400; text-align: center; margin: 40px 0 0;" align="center">{$city}</h4>
126+
</td>
127+
</tr>
128+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
129+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">
130+
<table class="invoice" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; text-align: left; width: 80%; margin: 40px auto;">
131+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
132+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">Hi,{$userid}<br style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">邮箱:{$usermail}</td>
133+
</tr>
134+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
135+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">
136+
<table class="invoice-items" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; margin: 0;">
137+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
138+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">今天的天气是:</td>
139+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather0}</td>
140+
</tr>
141+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
142+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top"> 明天的天气是:</td>
143+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather1}</td>
144+
</tr>
145+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
146+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">后天的天气是:</td>
147+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather2}</td>
148+
</tr>
149+
150+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
151+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">是否需要带伞?</td>
152+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$need}</td>
153+
</tr>
154+
155+
156+
</tbody></table>
157+
</td>
158+
</tr>
159+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
160+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">{$motd}</td>
161+
</tr>
162+
163+
</tbody></table>
164+
</td>
165+
</tr>
166+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
167+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">
168+
<a href="" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; color: #348eda; text-decoration: underline; margin: 0;"></a>
169+
</td>
170+
</tr>
171+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
172+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top"><a href="{$link}">{$appname}</a></td>
173+
</tr>
174+
</tbody></table>
175+
</td>
176+
</tr>
177+
</tbody></table>
178+
<div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
179+
<table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
180+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
181+
</tr>
182+
</tbody></table>
183+
</div>
184+
</div>
185+
</td>
186+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
187+
</tr>
188+
</tbody></table>
189+
LABELSS;
190+
191+
if(strstr($weather0,"")){
192+
$need = "需要带伞";
193+
$mailto=$usermail; //收件人
194+
$subject="今日有雨,注意带伞"; //邮件主题
195+
$body=$mai; //邮件内容
196+
sendmailto($mailto,$subject,$body);
197+
}
198+
else
199+
{
200+
$need = "不需要带伞";
201+
$mailto=$usermail; //收件人
202+
$subject="今天是个好天气"; //邮件主题
203+
$body=$mai; //邮件内容
204+
sendmailto($mailto,$subject,$body);
205+
};
206+
207+
208+
print_r($mai);
209+
210+
?>

config.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<meta http-equiv="content-type" content="text/html;charset=utf-8">
2+
<?php
3+
date_default_timezone_set("PRC");
4+
5+
require 'email.class.php';
6+
$userid = "Nchyn"; //用户名
7+
$location = "shanghai"; //用户物理地址
8+
$usermail = "[email protected]"; //用户邮箱
9+
$appname = "Nchyn's带伞提醒"; //应用名称
10+
$link = "http://weather.nchyn.com"; //应用主页
11+
$key = "your KEY";//和风天气KEY,请在api.hweather.com申请
12+
$api = "https://free-api.heweather.com/s6/weather/forecast?location={$location}&key={$key}";//json地址
13+
$str = file_get_contents($api);
14+
//echo "邮件发送完成".date('时间:Y年m月d日 H:i');
15+
function sendmailto($mailto, $mailsub, $mailbd)
16+
{
17+
//require_once ('email.class.php');
18+
//##########################################
19+
$smtpserver = "smtp.ym.163.com"; //SMTP服务器
20+
$smtpserverport = 25; //SMTP服务器端口
21+
$smtpusermail = "[email protected]"; //SMTP服务器的用户邮箱
22+
$smtpemailto = $mailto;
23+
$smtpuser = "[email protected]"; //SMTP服务器的用户帐号
24+
$smtppass = "yourpassword"; //SMTP服务器的用户密码
25+
$mailsubject = $mailsub; //邮件主题
26+
$mailsubject = "=?UTF-8?B?" . base64_encode($mailsubject) . "?="; //防止乱码
27+
$mailbody = $mailbd; //邮件内容
28+
//$mailbody = "=?UTF-8?B?".base64_encode($mailbody)."?="; //防止乱码
29+
$mailtype = "HTML"; //邮件格式(HTML/TXT),TXT为文本邮件. 139邮箱的短信提醒要设置为HTML才正常
30+
##########################################
31+
$smtp = new smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass); //这里面的一个true是表示使用身份验证,否则不使用身份验证.
32+
$smtp->debug = false; //是否显示发送的调试信息
33+
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
34+
35+
}
36+
?>

0 commit comments

Comments
 (0)