-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move secret settings into independent file
- Loading branch information
1 parent
03d9d2e
commit 98ae891
Showing
2 changed files
with
49 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
<?php | ||
|
||
// phpmailer | ||
use PHPMailer\PHPMailer\PHPMailer; | ||
require 'vendor/autoload.php'; | ||
|
||
date_default_timezone_set('Asia/Taipei'); | ||
// settings and secrets | ||
require 'setting.php'; | ||
|
||
$url = 'http://host/path/to/site'; | ||
$austin = '[email protected]'; | ||
$joyce = '[email protected]'; | ||
date_default_timezone_set($timezone); | ||
|
||
// mailer settings | ||
$mail = new PHPMailer; | ||
$mail->isSMTP(); | ||
$mail->CharSet = 'UTF-8'; | ||
|
@@ -19,43 +20,47 @@ | |
$mail->SMTPAuth = true; | ||
|
||
// SMTP Auth | ||
$mail->Username = '[email protected]'; | ||
$mail->Password = '30fLS_439GW1cvnslDLS29d'; | ||
$mail->Username = $auth_google['user']; | ||
$mail->Password = $auth_google['password']; | ||
|
||
$dbhost = '127.0.0.1'; | ||
$dbuser = 'military'; | ||
$dbpass = 'militarysucks'; | ||
$dbname = 'military'; | ||
|
||
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); | ||
$mysqli->query("SET NAMES utf8"); | ||
// create database connection | ||
$mysqli = new mysqli( | ||
$database['host'], | ||
$database['user'], | ||
$database['password'], | ||
$database['name'] | ||
); | ||
|
||
if (mysqli_connect_errno() ) { | ||
echo 'Failed to connect to MySQL: ' . mysqli_connect_error(); | ||
} | ||
|
||
$mysqli->query("SET NAMES utf8"); | ||
|
||
if (isset($_POST['message']) && $_POST['message'] != '') { | ||
$new = $_POST['message']; | ||
$new_content = $_POST['message']; | ||
|
||
if (isset($_POST['user']) && ($_POST['user'] == 'A' || $_POST['user'] == 'J') ) { | ||
$user = $_POST['user']; | ||
$now = date("Y-m-d H:i:s"); | ||
$new_user = $_POST['user']; | ||
$new_time = date("Y-m-d H:i:s"); | ||
|
||
$sql = 'INSERT INTO messages (content, user, datetime) VALUES ("'.$new_content.'", "'.$new_user.'", "'.$new_time.'")'; | ||
|
||
$sql = 'INSERT INTO messages (content, user, datetime) VALUES ("'.$new.'", "'.$user.'", "'.$now.'")'; | ||
if ($mysqli->query($sql) != TRUE) { | ||
echo "Error: " . $mysqli->error; | ||
} else { | ||
|
||
} else { | ||
// notify joyce | ||
if ($user == 'A') { | ||
if ($new_user == 'A') { | ||
// Recipients | ||
$mail->setFrom($austin, 'Austin'); | ||
$mail->addAddress($joyce, 'JoyceHuang'); | ||
$mail->setFrom($users['austin'], 'Austin'); | ||
$mail->addAddress($users['joyce'], 'JoyceHuang'); | ||
|
||
// Mail Content | ||
$mail->isHTML(true); | ||
$mail->Subject = '來自Military Tunnel的新訊息'; | ||
$mail->Body = '<a href="'.$url.'" style="color: #164187;">'.$new.'</a>'; | ||
$mail->AltBody = $new; | ||
$mail->Body = '<a href="'.$home_url.'" style="color: #164187;">'.$new_content.'</a>'; | ||
$mail->AltBody = $new_content; | ||
|
||
if (!$mail->send()) { | ||
echo "Mailer Error: " . $mail->ErrorInfo; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
$timezone = 'Asia/Taipei'; | ||
$home_url = 'http://domain.name/path'; | ||
|
||
$users = array( | ||
'austin' => '[email protected]', | ||
'joyce' => '[email protected]' | ||
); | ||
|
||
$auth_google = array( | ||
'user' => '[email protected]', | ||
'password' => 'secret' | ||
); | ||
|
||
$database = array( | ||
'host' => 'secret', | ||
'user' => 'secret', | ||
'password' => 'secret', | ||
'name' => 'secret' | ||
); | ||
?> |