폼메일
컨텐츠 정보
- 16,481 조회
- 8 추천
- 목록
본문
function mailer_header()
{
echo "
<html>
<head>
<title>BUGZZANG FORMMAIL</title>
<style>
BODY { scrollbar-face-color:#dddddd; scrollbar-shadow-color:aaaaaa; scrollbar-highlight-color:#ffffff; scrollbar-3dlight-color:#999999; scrollbar-darkshadow-color:#999999; scrollbar-track-color:white; scrollbar-arrow-color:white; font-size:9pt; font-family:verdana;}
table,tr,td,input,textarea {font-size:9pt; font-family:verdana; }
input,textarea {border:solid 1; }
.noborder {border:0; }
</style>
</head>
<body>
"
}
function mailer_footer()
{
echo "
</body>
</html>
"
}
function error_message($msg)
{
mailer_header();
echo "<SCRIPT>alert(\\"오류: $msg\\");history.back()</SCRIPT>"
mailer_footer();
exit;
}
function user_message($msg)
{
mailer_header();
echo "<SCRIPT>alert(\\"$msg\\");self.close()</SCRIPT>"
mailer_footer();
exit;
}
function mail_form()
{
$adminmail="user1@bugzzang.com"
echo "
<form name=mailform method=post action='$PHP_SELF' enctype='multipart/form-data'>
<input type=hidden name=action value=send_mail>
<table>
<tr>
<td align=right>To : </td><td><input type=text name=mail_to size=30 value='$adminmail'></td>
</tr>
<tr>
<td align=right>From : </td><td><input type=text name=mail_from size=30></td>
</tr>
<tr>
<td align=right>Subject : </td><td><input type=text name=mail_subject size=50></td>
</tr>
<tr>
<td align=right>Message : </td>
<td>
<textarea name=mail_body cols=50 rows=10></textarea><br>
<input type=radio name=mail_type value='text' class=noborder checked>text
<input type=radio name=mail_type value='html' class=noborder>html
</td>
</tr>
<tr>
<td align=right>File : </td><td><input type=file name=userfile size=35></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value='전송하기'>
<input type=reset value='다시쓰기'>
</td>
</tr>
</table>
</form>
"
}
function send_mail()
{
global $mail_to, $mail_from;
global $mail_body, $mail_subject;
global $userfile, $userfile_type, $userfile_name, $userfile_size;
global $mail_type;
$mail_parts["mail_type"] = $mail_type;
$mail_parts["userfile"] = $userfile;
$mail_parts["userfile_type"] = $userfile_type;
$mail_parts["userfile_name"] = $userfile_name;
$mail_parts["userfile_size"] = $userfile_size;
$mail_parts["mail_to"] = $mail_to;
$mail_parts["mail_from"] = $mail_from;
$mail_parts["mail_subject"] = trim($mail_subject);
$mail_parts["mail_body"] = $mail_body;
if(my_mail($mail_parts))
user_message("'$mail_subject'란 제목의 메일을 보냈습니다.");
else error_message("'$mail_subject'란 제목의 메일 전송을 시도하던 중 오류가 발생했습니다.");
}
function my_mail($mail_parts)
{
$mail_to = $mail_parts["mail_to"];
$mail_from = $mail_parts["mail_from"];
$mail_subject = $mail_parts["mail_subject"];
$mail_body = $mail_parts["mail_body"];
$mail_type = $mail_parts["mail_type"];
$userfile = $mail_parts["userfile"];
$userfile_type = $mail_parts["userfile_type"];
$userfile_name = $mail_parts["userfile_name"];
$userfile_size = $mail_parts["userfile_size"];
if(empty($mail_to)) error_message("받을 사람이 없습니다!");
if(empty($mail_subject)) error_message("제목이 없습니다!");
if(empty($mail_body)) error_message("본문이 없습니다! ");
$mail_to = str_replace("", ",", $mail_to);
$mail_headers = ''
if(!empty($mail_from)) $mail_headers .= "From: $mail_from\\n"
$mail_subject = stripslashes($mail_subject);
$mail_body = stripslashes($mail_body);
if($userfile_size > 0)
{
$mail_boundary = md5(uniqid(time()));
$mail_headers .= "MIME-Version: 1.0\\n"
$mail_headers .= "Content-type: multipart/mixed;boundary=\\"$mail_boundary\\"\\n\\n"
$mail_headers .= "This is a multi-part message in MIME format.\\n\\n"
$fp = fopen($userfile, "r");
$file = fread($fp, filesize($userfile));
$file = chunk_split(base64_encode($file));
$new_mail_body = "--$mail_boundary\\n"
$new_mail_body .= "Content-type:text/plain;charset=euc-kr\\n"
$new_mail_body .= "Content-transfer-encoding:8bit\\n\\n"
$new_mail_body .= "$mail_body\\n"
$new_mail_body .= "--$mail_boundary\\n"
if(!empty($userfile_type)) $mime_type = $userfile_type;
else $mime_type = "application/octet-stream"
$new_mail_body .= "Content-type:$mime_type;name=$userfile_name\\n"
$new_mail_body .= "Content-transfer-encoding:base64\\n\\n"
$new_mail_body .= $file . "\\n\\n"
$new_mail_body .= "--$mail_boundary--"
$mail_body = $new_mail_body;
}
else if($mail_type == 'html')
{
$mail_headers .= "Content-type: text/html; charset=euc-kr\\n"
$mail_headers .= "Content-transfer-encoding:8bit\\n\\n"
}
else
{
$mail_headers .= "Content-type: text/plain; charset=euc-kr\\n"
$mail_headers .= "Content-transfer-encoding:8bit\\n\\n"
}
return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
}
switch ($action)
{
case "send_mail":
mailer_header();
send_mail();
mailer_footer();
break;
case "mail_form":
mailer_header();
mail_form();
mailer_footer();
break;
default:
mailer_header();
mail_form();
mailer_footer();
break;
}
{
echo "
<html>
<head>
<title>BUGZZANG FORMMAIL</title>
<style>
BODY { scrollbar-face-color:#dddddd; scrollbar-shadow-color:aaaaaa; scrollbar-highlight-color:#ffffff; scrollbar-3dlight-color:#999999; scrollbar-darkshadow-color:#999999; scrollbar-track-color:white; scrollbar-arrow-color:white; font-size:9pt; font-family:verdana;}
table,tr,td,input,textarea {font-size:9pt; font-family:verdana; }
input,textarea {border:solid 1; }
.noborder {border:0; }
</style>
</head>
<body>
"
}
function mailer_footer()
{
echo "
</body>
</html>
"
}
function error_message($msg)
{
mailer_header();
echo "<SCRIPT>alert(\\"오류: $msg\\");history.back()</SCRIPT>"
mailer_footer();
exit;
}
function user_message($msg)
{
mailer_header();
echo "<SCRIPT>alert(\\"$msg\\");self.close()</SCRIPT>"
mailer_footer();
exit;
}
function mail_form()
{
$adminmail="user1@bugzzang.com"
echo "
<form name=mailform method=post action='$PHP_SELF' enctype='multipart/form-data'>
<input type=hidden name=action value=send_mail>
<table>
<tr>
<td align=right>To : </td><td><input type=text name=mail_to size=30 value='$adminmail'></td>
</tr>
<tr>
<td align=right>From : </td><td><input type=text name=mail_from size=30></td>
</tr>
<tr>
<td align=right>Subject : </td><td><input type=text name=mail_subject size=50></td>
</tr>
<tr>
<td align=right>Message : </td>
<td>
<textarea name=mail_body cols=50 rows=10></textarea><br>
<input type=radio name=mail_type value='text' class=noborder checked>text
<input type=radio name=mail_type value='html' class=noborder>html
</td>
</tr>
<tr>
<td align=right>File : </td><td><input type=file name=userfile size=35></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value='전송하기'>
<input type=reset value='다시쓰기'>
</td>
</tr>
</table>
</form>
"
}
function send_mail()
{
global $mail_to, $mail_from;
global $mail_body, $mail_subject;
global $userfile, $userfile_type, $userfile_name, $userfile_size;
global $mail_type;
$mail_parts["mail_type"] = $mail_type;
$mail_parts["userfile"] = $userfile;
$mail_parts["userfile_type"] = $userfile_type;
$mail_parts["userfile_name"] = $userfile_name;
$mail_parts["userfile_size"] = $userfile_size;
$mail_parts["mail_to"] = $mail_to;
$mail_parts["mail_from"] = $mail_from;
$mail_parts["mail_subject"] = trim($mail_subject);
$mail_parts["mail_body"] = $mail_body;
if(my_mail($mail_parts))
user_message("'$mail_subject'란 제목의 메일을 보냈습니다.");
else error_message("'$mail_subject'란 제목의 메일 전송을 시도하던 중 오류가 발생했습니다.");
}
function my_mail($mail_parts)
{
$mail_to = $mail_parts["mail_to"];
$mail_from = $mail_parts["mail_from"];
$mail_subject = $mail_parts["mail_subject"];
$mail_body = $mail_parts["mail_body"];
$mail_type = $mail_parts["mail_type"];
$userfile = $mail_parts["userfile"];
$userfile_type = $mail_parts["userfile_type"];
$userfile_name = $mail_parts["userfile_name"];
$userfile_size = $mail_parts["userfile_size"];
if(empty($mail_to)) error_message("받을 사람이 없습니다!");
if(empty($mail_subject)) error_message("제목이 없습니다!");
if(empty($mail_body)) error_message("본문이 없습니다! ");
$mail_to = str_replace("", ",", $mail_to);
$mail_headers = ''
if(!empty($mail_from)) $mail_headers .= "From: $mail_from\\n"
$mail_subject = stripslashes($mail_subject);
$mail_body = stripslashes($mail_body);
if($userfile_size > 0)
{
$mail_boundary = md5(uniqid(time()));
$mail_headers .= "MIME-Version: 1.0\\n"
$mail_headers .= "Content-type: multipart/mixed;boundary=\\"$mail_boundary\\"\\n\\n"
$mail_headers .= "This is a multi-part message in MIME format.\\n\\n"
$fp = fopen($userfile, "r");
$file = fread($fp, filesize($userfile));
$file = chunk_split(base64_encode($file));
$new_mail_body = "--$mail_boundary\\n"
$new_mail_body .= "Content-type:text/plain;charset=euc-kr\\n"
$new_mail_body .= "Content-transfer-encoding:8bit\\n\\n"
$new_mail_body .= "$mail_body\\n"
$new_mail_body .= "--$mail_boundary\\n"
if(!empty($userfile_type)) $mime_type = $userfile_type;
else $mime_type = "application/octet-stream"
$new_mail_body .= "Content-type:$mime_type;name=$userfile_name\\n"
$new_mail_body .= "Content-transfer-encoding:base64\\n\\n"
$new_mail_body .= $file . "\\n\\n"
$new_mail_body .= "--$mail_boundary--"
$mail_body = $new_mail_body;
}
else if($mail_type == 'html')
{
$mail_headers .= "Content-type: text/html; charset=euc-kr\\n"
$mail_headers .= "Content-transfer-encoding:8bit\\n\\n"
}
else
{
$mail_headers .= "Content-type: text/plain; charset=euc-kr\\n"
$mail_headers .= "Content-transfer-encoding:8bit\\n\\n"
}
return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
}
switch ($action)
{
case "send_mail":
mailer_header();
send_mail();
mailer_footer();
break;
case "mail_form":
mailer_header();
mail_form();
mailer_footer();
break;
default:
mailer_header();
mail_form();
mailer_footer();
break;
}
관련자료
댓글 0
등록된 댓글이 없습니다.