Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active October 10, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/d24f287b7236622afd0834c853773a66 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/d24f287b7236622afd0834c853773a66 to your computer and use it in GitHub Desktop.
Mailを転送ロジック->Jsonを出力先のHtmlにdump
<?php
// バッファリング開始
ob_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="application/json; charset=utf-8" />
<title></title>
</head>
<body>
<br>
<br>
State =
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
require 'dbClass.php';
$mail = new PHPMailer();
$mail->isSMTP();
#$mail->SMTPDebug = 1;
$mail->Encoding = "7bit";
$mail->CharSet = '"UTF-8"';
$mail->Debugoutput = 'html';
$mail->SMTPSecure = "tls";
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->IsHTML(false);
$mail->Username = 'Username';
$mail->Password = 'Password';
#$mail->AddAddress('daisukeseiyu@yahoo.co.jp');
$mail->From = 'dbank0208@gmail.com';
$mail->FromName = mb_encode_mimeheader("表示名","ISO-2022-JP","UTF-8"); // "表示名" <メールアドレス>
$mail->Body = mb_convert_encoding("本文","UTF-8","auto");
$json = file_get_contents('php://input');
$json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
$obj = json_decode($json);
if ($obj === NULL) {
return;
}
########################################################################
#日時取得
date_default_timezone_set('Asia/Japan');
$datetime =date("Y/m/d H:i");
########################################################################
#共通のホワイトリスト
#insert_CommonWhite_List(文字列で代入);
#ホワイトリスト
#insert_WhiteList_List($obj->{'電話番号'},$obj->{'着信'});
#ログ
#insert_LogTable(strval($datetime),$obj->{'着信'},$obj->{'応答'},$obj->{'電話番号'});
#print print_r($LogTable_Datetime);
#print print_r($LogTable_Incoming);
#print print_r($LogTable_Response);
#print print_r($SubscribeList_ContractorNumber);
#契約者情報
#insert_SubscribeList($obj->{'電話番号'},"daisukeseiyu@yahoo.ne.jp","xdq4zex[,");
########################################################################
echo "開始 ". date('h:i:s',time()) . "\n";
for($i=0;$i<3;$i++)
{
if($i != 0)
{
AboutDelay($start,3); // start から3秒間まで待つ。
}
$start = time();
//共通のホワイトリストの設定
if (!(in_array($obj->{'着信'}, $Commonwhite_List))) {
//ホワイトリストの設定
if (!(in_array($obj->{'着信'}, $WhiteList_ContractorList)) && !(in_array($obj->{'着信'}, $WhiteList_PhoneNumberList))) {
for ($i=0; $i< count($SubscribeList_Mail)+1; $i++) {
if ($obj->{'電話番号'} == $SubscribeList_ContractorNumber[$i]) {
$mail->AddAddress($SubscribeList_Mail[$i]);
}
}
if ($obj->{'応答'} == "" ){
$mail->Subject = mb_encode_mimeheader("件名 着信","ISO-2022-JP", "UTF-8");
$mail->Body = mb_convert_encoding("契約者様の電話帳にはない電話から、着信がありました。","UTF-8","auto");
if (!$mail->send()) {
echo "送信エラー " . $mail->ErrorInfo;
} else {
echo " $json 着信メールを送信しました" . "\n";
}
}else{
$mail->Subject = mb_encode_mimeheader("件名 応答","ISO-2022-JP", "UTF-8");
$mail->Body = mb_convert_encoding("契約者様の電話帳にはない電話から着信があり、契約者様が応答しました。","UTF-8","auto");
if (!$mail->send()) {
echo "送信エラー " . $mail->ErrorInfo;
} else {
echo " $json 応答メールを送信しました" . "\n";
}
}
}
}
// なんかの処理をここに記述する。
}
echo "終了 ". date('h:i:s',time()) . "\n";
?>
<br><br><br><br>
</body>
</html>
<?php
// 同階層の 出力先のHtml にphp実行結果を出力
file_put_contents( '先のHtm出力l', ob_get_contents() );
// 出力用バッファをクリアしてオフ
ob_end_clean();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment