<?php
mb_language("Japanese");
mb_internal_encoding("UTF-8");

require_once '../include/server_check.php';
require_once '../include/config.php';
require_once '../include/functions.php';
require_once '../include/mail_data_create.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;
//$headers['Content-Transfer-Encoding'] = "BASE64";

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

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

// 本文
// パスワードを置換する
$randompass = "ramdompass";
$content = sprintf(MAIL_CONTENT,$randompass);

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