<?
//mb_language("Ja");
//mb_internal_encoding("EUC-JP") ;
$name = "april snow";//管理者名。半角英数字、
$to = "signinafragrance@snow.odn.ne.jp";//管理者のメールアドレス。
$title1 = "mail from april snow";//管理者宛のメールのタイトル。日本語可、
$title2 = "thanx 4 ur message!";//送り先のメール(複写分)のタイトル。日本語可、
$title1 = mb_convert_encoding($title1,"EUC-JP","auto");
$title2 = mb_convert_encoding($title2,"EUC-JP","auto");
$author = $_POST['author'];
$email = $_POST['email'];
$url = $_POST['url'];
$cc = $_POST['cc'];
$text = $_POST['text'];
if(get_magic_quotes_gpc()){
$author = stripslashes($author);
$email = stripslashes($email);
$url = stripslashes($url);
$text = stripslashes($text);
}
$author = sprintf("%s",$author);
$email = sprintf("%s",$email);
$url = sprintf("%s",$url);
$text = sprintf("%s",$text);
$TM = date("Y/m/d(D) H:i:s");
$PX = $_SERVER['HTTP_FORWARDED'];
$UA = $_SERVER['HTTP_USER_AGENT'];
$RA = $_SERVER['REMOTE_ADDR'];
if($TM == ""){$TM = "undefined";}
if($PX == ""){$PX = "none";}
if($UA == ""){$UA = "undefined";}
if($RA == ""){$RA = "undefined";}
$error = "";
if($author == ""){$error .= "please input your name.\r\n";}
if($email == ""){$error .= "please input your e-mail address.\r\n";}
if($text == ""){$error .= "please input your message.\r\n";}
if(strlen($author) > 50){$error .= "sorry,name is restricted to 25 characters with 2 byte value.\r\n";}
if(strlen($email) > 100){$error .= "sorry,e-mail is restricted to 50 characters with 2 byte value.\r\n";}
if(strlen($url) > 100){$error .= "sorry,url is restricted to 50 characters with 2 byte value.\r\n";}
if(strlen($text) > 2000){$error .= "sorry,message is restricted to 1000 characters with 2 byte value.\r\n";}
/*メールアドレスのチェック(正規表現のみ)
if($email != ""){
$format1 = "^[^@]+@[^@]+[^@]+$";
if(!ereg($format1,$email)){$error .= "e-mail address is incorrect.\n";}
}
*/
if($email != ""){
$format1 = "^[^@]+@[^@]+[^@]+$";
if(!ereg($format1,$email)){
$error .= "e-mail address is incorrect.\n";
}else{
$at = split("@",$email);
if(strlen($at[0]) < 2){
$error .= "e-mail address is incorrect.\n";
}else{
if(strpos($at[1],".") == false){
$error .= "e-mail address is incorrect.\n";
}else{
$dot = split("\.",$at[1]);
$cnt = count($dot);
if($cnt < 2){
$error .= "e-mail address is incorrect.\n";
}else{
for($i=0; $i<$cnt; $i++){
if(strlen($dot[$i]) < 2){
$error = "e-mail address is incorrect.\n";
}
}
}
}
}
}
}
/*URLのチェック(正規表現のみ)
if($url != ""){
$format2 = "(https?|ftp):\/\/.+";
if(!ereg($format2,$url)){$error .= "url is incorrect.\n";}
}else{
$url = "none";
}
*/
if($url != ""){
$format2 = "(https?|ftp):\/\/.+";
if(!ereg($format2,$url)){
$error .= "url is incorrect.\n";
}else{
if(strpos($url,".") == false){
$error .= "url is incorrect.\n";
}else{
$dot = split("\.",$url);
$cnt = count($dot);
if($cnt < 2){
$error .= "url is incorrect.\n";
}else{
for($i=0; $i<$cnt; $i++){
if(strlen($dot[$i]) < 2){
$error .= "url is incorrect.\n";
}
}
}
}
}
}else{
$url = "none";
}
if($error != ""){
echo "<font color=\"red\">Correct errors,if any.</font>";
echo "<pre>$error</pre>";
exit;
}else{
//管理者宛のメッセージには、アクセスログを追記。
$message1 = "";
$message1 .= "name : " . $author . "\r\n";
$message1 .= "e-mail : " . $email . "\r\n";
$message1 .= "url : " . $url . "\r\n";
$message1 .= "message : " . "\r\n" . $text . "\r\n\r\n";
$message1 .= "date : " . $TM . "\r\n";
$message1 .= "proxy : " . $PX . "\r\n";
$message1 .= "user agent : " . $UA . "\r\n";
$message1 .= "remote address : " . $RA;
//送り先のメッセージには、アクセスログを控除。
$message2 = "";
$message2 .= "name : " . $author . "\r\n";
$message2 .= "e-mail : " . $email . "\r\n";
$message2 .= "url : " . $url . "\r\n";
$message2 .= "message : " . "\r\n" . $text;
$message1 = mb_convert_encoding($message1,"EUC-JP","auto");
$message2 = mb_convert_encoding($message2,"EUC-JP","auto");
//ヘッダー。URLのみ表示、
//$header1 = "From:" . $email . "\r\n" . "Reply-To:" . $email . "\r\n";
//$header2 = "From:" . $to . "\r\n" . "Reply-To:" . $to . "\r\n";
//ヘッダー。"$name"は、半角英数字のみ有効(標準仕様)。
$header1 = "From:" . $email . "\r\n" . "Reply-To:" . $email . "\r\n";
$header2 = "From:" . $name . "<" . $to . ">" . "\r\n" . "Reply-To:" . $name . "<" . $to . ">" . "\r\n";
//ヘッダー。"$name"は、半角英数字のみ有効("$author"に、文字化けの可能性あり)。
//$header1 = "From:" . $author . "<" . $email . ">" . "\r\n" . "Reply-To:" . $author . "<" . $email . ">" . "\r\n";
//$header2 = "From:" . $name . "<" . $to . ">" . "\r\n" . "Reply-To:" . $name . "<" . $to . ">" . "\r\n";
//ヘッダー。"$name"の日本語化。おそらくMacでは、文字化け必至...
//$header1 = "From:" . mb_encode_mimeheader($author) . "<" . $email . ">" . "\r\n" . "Reply-To:" . mb_encode_mimeheader($author) . "<" . $email . ">" . "\r\n";
//$header2 = "From:" . mb_encode_mimeheader("草森冬弥") . "<" . $to . ">" . "\r\n" . "Reply-To:" . mb_encode_mimeheader("草森冬弥") . "<" . $to . ">" . "\r\n";
if($cc != cc){
mb_send_mail($to,$title1,$message1,$header1);
}else{
mb_send_mail($to,$title1,$message1,$header1);
mb_send_mail($email,$title2,$message2,$header2);
}
//Webサーバーに保存するログの種類。
//1年ごと($Y)、1月ごと($M)、1日ごと($D)、1件ごと($S),全件($F),
//"$H = fopen($F,"a") ... "の$Fの部分を変更。デフォルトは全件。
$Y = date("Y");
$M = date("Ym");
$D = date("Ymd");
$S = date("YmdHis");
$Y = sprintf("./data/%s.txt",$Y);
$M = sprintf("./data/%s.txt",$M);
$D = sprintf("./data/%s.txt",$D);
$S = sprintf("./data/%s.txt",$S);
//フォルダ"data"を作成。パーミッションは、777、
//要アクセス制限。パスワード保護(.htaccess,.htpasswd)ほか、
$F = "./data/mail.txt";
$H = fopen($F,"a") or die("error is occurred while opening file.");
flock($H,LOCK_EX);
$L = sprintf("%s,%s,%s,%s,%s,%s,%s,%s\r\n",$author,$email,$url,$text,$TM,$PX,$UA,$RA);
$L = mb_convert_encoding($L,"Shift_JIS","auto");
fputs($H,$L);
flock($H,LOCK_UN);
fclose($H);
//完了画面へリダイレクト。
header("Location:maildone.php");
exit;
}
?>