묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
파일첨부 폼메일관련 질문
2006.07.12 20:34
<style type="text/css">
p {font-size:9pt; color:#4D4D4D; line-height:160%;}
.inputform {
border-width:1px; border-color:#B9B9B9; border-style:solid;
font-size:9pt; color:#737373; font-family:Verdana;
}
</style>
<?
if($mode=="send"){
$tomail = "sissy77@hanmail.net";
// 결과메시지 출력
function result($message) {
?>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<p align="center"><?=$message?><br><br><input type=button value="Back" onclick="history.back()"></p>
</td>
</tr>
</table>
<?
exit;
}
if(!$from) result("보내는 사람의 이름을 입력하세요.");
if(!$frommail) result("보내는 사람의 메일을 입력하세요.");
if(!$subject) result("제목을 입력하세요.");
if(!$content) result("내용을 입력하세요.");
// 메일보내기 형식
$mailheaders = "Return-Path: $frommailrn";
$mailheaders .= "From: $from <$frommail>rn";
$mailheaders .= "Reply-To: $frommailrn";
$mailheaders .= "MIME-Version: 1.0rn";
// 파일 첨부시
if ($userfile_name && $userfile_size){
$filename=basename($userfile_name);
$result=fopen($userfile,"r");
$file=fread($result,$userfile_size);
fclose($result);
if ($userfile_type == ""){
$userfile_type = "application/octet-stream";
}
$boundary = "--------" . uniqid("part");
$mailheaders .= "Content-Type: multipart/mixed; boundary="$boundary"";
$body = "This is a multi-part message in MIME format.rnrn";
$body .= "--$boundaryrn";
$body .= "Content-Type: text/html; charset=euc-krrn";
$body .= "Content-Transfer-Encoding: 8bitrnrn";
if($html){
$body .= nl2br(stripslashes($content)) . "rnrn";
}else{
$body .= nl2br(htmlspecialchars(stripslashes($content))) . "rnrn";
}
$body .= "--$boundaryrn";
$body .= "Content-Type: $userfile_type; name="$filename"rn";
$body .= "Content-Transfer-Encoding: base64rnrn";
$body .= ereg_replace("(.{80})","\1rn",base64_encode($file));
$body .= "rn--$boundary" . "rn";
}
// 파일 미첨부시
else{
$mailheaders .= "content-Type: text/html; charset=euc-krrn";
if($html){
$body = nl2br(stripslashes($content)) . "rnrn";
}else{
$body = nl2br(htmlspecialchars(stripslashes($content))) . "rnrn";
}
}
$result=mail( $tomail , $subject , $body , $mailheaders );
// 결과 출력
if($result){
result("메일을 보냈습니다.");
}else{
result("메일 보내기에 실패했습니다.");
}
}
?>
<form method="post" enctype="multipart/form-data" action="<?=$PHP_SELF?>?mode=send">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="50" height="25">
<p align="center">이름</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="from" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">메일</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="frommail" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">제목</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="subject" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td>
<p align="center">내용</p>
</td>
<td width="5">
</td>
<td>
<p><INPUT TYPE="radio" NAME="html" value="" checked> Text <INPUT TYPE="radio" NAME="html" value="html"> Html</p>
</td>
</tr>
<tr>
<td>
</td>
<td width="5">
</td>
<td>
<p><textarea name="content" style="width:300; height:150;"></textarea></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">첨부</p>
</td>
<td width="5">
</td>
<td>
<p><input type="file" name="userfile" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25" colspan="3">
<p align="center"><input type="submit" value="보내기"></p>
</td>
</tr>
</table>
</form>
p {font-size:9pt; color:#4D4D4D; line-height:160%;}
.inputform {
border-width:1px; border-color:#B9B9B9; border-style:solid;
font-size:9pt; color:#737373; font-family:Verdana;
}
</style>
<?
if($mode=="send"){
$tomail = "sissy77@hanmail.net";
// 결과메시지 출력
function result($message) {
?>
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<p align="center"><?=$message?><br><br><input type=button value="Back" onclick="history.back()"></p>
</td>
</tr>
</table>
<?
exit;
}
if(!$from) result("보내는 사람의 이름을 입력하세요.");
if(!$frommail) result("보내는 사람의 메일을 입력하세요.");
if(!$subject) result("제목을 입력하세요.");
if(!$content) result("내용을 입력하세요.");
// 메일보내기 형식
$mailheaders = "Return-Path: $frommailrn";
$mailheaders .= "From: $from <$frommail>rn";
$mailheaders .= "Reply-To: $frommailrn";
$mailheaders .= "MIME-Version: 1.0rn";
// 파일 첨부시
if ($userfile_name && $userfile_size){
$filename=basename($userfile_name);
$result=fopen($userfile,"r");
$file=fread($result,$userfile_size);
fclose($result);
if ($userfile_type == ""){
$userfile_type = "application/octet-stream";
}
$boundary = "--------" . uniqid("part");
$mailheaders .= "Content-Type: multipart/mixed; boundary="$boundary"";
$body = "This is a multi-part message in MIME format.rnrn";
$body .= "--$boundaryrn";
$body .= "Content-Type: text/html; charset=euc-krrn";
$body .= "Content-Transfer-Encoding: 8bitrnrn";
if($html){
$body .= nl2br(stripslashes($content)) . "rnrn";
}else{
$body .= nl2br(htmlspecialchars(stripslashes($content))) . "rnrn";
}
$body .= "--$boundaryrn";
$body .= "Content-Type: $userfile_type; name="$filename"rn";
$body .= "Content-Transfer-Encoding: base64rnrn";
$body .= ereg_replace("(.{80})","\1rn",base64_encode($file));
$body .= "rn--$boundary" . "rn";
}
// 파일 미첨부시
else{
$mailheaders .= "content-Type: text/html; charset=euc-krrn";
if($html){
$body = nl2br(stripslashes($content)) . "rnrn";
}else{
$body = nl2br(htmlspecialchars(stripslashes($content))) . "rnrn";
}
}
$result=mail( $tomail , $subject , $body , $mailheaders );
// 결과 출력
if($result){
result("메일을 보냈습니다.");
}else{
result("메일 보내기에 실패했습니다.");
}
}
?>
<form method="post" enctype="multipart/form-data" action="<?=$PHP_SELF?>?mode=send">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="50" height="25">
<p align="center">이름</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="from" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">메일</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="frommail" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">제목</p>
</td>
<td width="5">
</td>
<td>
<p><input type="text" name="subject" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td>
<p align="center">내용</p>
</td>
<td width="5">
</td>
<td>
<p><INPUT TYPE="radio" NAME="html" value="" checked> Text <INPUT TYPE="radio" NAME="html" value="html"> Html</p>
</td>
</tr>
<tr>
<td>
</td>
<td width="5">
</td>
<td>
<p><textarea name="content" style="width:300; height:150;"></textarea></p>
</td>
</tr>
<tr>
<td height="25">
<p align="center">첨부</p>
</td>
<td width="5">
</td>
<td>
<p><input type="file" name="userfile" style="width:300" class="inputform"></p>
</td>
</tr>
<tr>
<td height="25" colspan="3">
<p align="center"><input type="submit" value="보내기"></p>
</td>
</tr>
</table>
</form>
그런데 파일을 첨부해서 보내면 메일 내용이 하나도 없이 백지로 보내지네요..