<?php
chdir(__DIR__);

require_once '../include/server_check.php';
require_once '../include/functions.php';
require_once '../include/db.php';
require_once '../include/config.php';

mb_language("Japanese");
mb_internal_encoding("UTF-8");
require_once '../include/mail_data_demand.php';


if(SERVER_CHECK === 1){
	// 本番
	$to = "hirota@apteq.jp";
	$from = mail_from;
} else {
	// 開発
	$to = "hirota@apteq.jp";
	$from = "test@demo55.jp";
}

$headers = [];

$charset = "UTF-8";
$headers['MIME-Version'] = "1.0";

$From_name = "入籍指輪システム";
//$From_encoded = mb_convert_encoding($From_name, 'UTF-8', 'AUTO'); // mb_encode_mimeheaderに渡す前にUTF-8に変換しなくてはダメ
$From_address = $from;
$headers['From'] = mb_encode_mimeheader($From_name, 'UTF-8') ."<". $From_address .">";
$headers['Content-Type'] = "text/plain; charset=".$charset;
$headers['Reply-to'] = $From_address;
$headers['Sender'] = $From_address;
$headers['Return-Path'] = $From_address;

//配列から連結させる
foreach ($headers as $key => $val) {
	$arrheader[] = $key . ': ' . $val;
}
$strHeader = implode("\n", $arrheader);

// テンプレートを置換する
// タイトル
$title = MAIL_TITLE;

// 本文
// 名前を置換する
$content = sprintf(MAIL_CONTENT,$name);

if(!mail($to, $title, $content, $strHeader,"-f {$From_address}")){
	// メールの送信に失敗
	echo "メール送信に失敗\n";
}

echo SERVER_CHECK;
echo "\n";
echo $DIR_PATH;
