演示
演示1 演示2代码
HTML表单查看源文件复制就行新建send.php,代码如下
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$content = trim($_POST['content'] ?? '');
if(!$title || !$content){
echo json_encode(['code'=>0,'msg'=>'标题或内容不能为空']);
exit;
}
// ⚠️ 你的 PushPlus Token
$token = "你的PushPlusToken";
// PushPlus 邮件推送和微信推送一样,只是通过你注册的邮箱接收
$data = [
"token" => $token,
"title" => $title,
"content" => $content,
"template" => "html" // html 或 text
// "channel" => "mail" // 如果你想强制走邮件通道可以加这个参数
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.pushplus.plus/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response; // 返回结果给前端
} else {
echo json_encode(['code'=>0,'msg'=>'非法请求']);
}
?>