묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
폼메일에 파일첨부하려는데요...(PHP)
2004.01.02 03:43
폼메일을 만들어서 파일도 첨부하여야 하는데...
잘 안되네요. ㅜ,.ㅜ
저는 왕초보인데 영진책(PHP4_30일완성)보고 따라해 봤슴다.
근데...
파일을 첨부하면 내용글도 전달이 않되고, 첨부파일도 따라가지 않습니다.
파일을 첨부하지 않으면 정상적으로 내용글만 전달됩니다.
==== 메일쓰는 페이지의 폼 부분은 아래와 같구요 ====
<form action="sendmail.php" method="post" name="forms" id="forms" enctype="multipart/form-data">
<br>
<table width="575" border="0" cellspacing="4">
<tr>
<td width="200" valign="bottom"><div align="right" class="style3 style4"><span class="style6">*</span> <span class="style9 style7">성 명 (Name)</span></div></td>
<td width="354">
<input name="name" type="text" class="input" id="name" size="30">
</td>
</tr>
<tr>
<td valign="bottom"><div align="right" class="style5"><span class="style6">*</span> <span class="style7">메 일 (E-mail)</span> </div> <div align="right" class="style5"> </div></td>
<td>
<input name="e_mail" type="text" id="e_mail" size="58">
</td>
</tr>
<tr>
<td valign="bottom"><div align="right" class="style5"><span class="style6">*</span> <span class="style7">제 목 (Subject)</span> </div></td>
<td>
<input name="subject" type="text" id="subject" size="58">
</td>
</tr>
<tr>
<td valign="top"><div align="right" class="style5">
<p><br>
<span class="style6">*</span> <span class="style7">내 용 (Contents)</span> </p>
</div></td>
<td>
<textarea name="contents" cols="57" rows="8" id="contents"></textarea>
</td>
</tr>
<tr>
<td valign="bottom"><div align="right"><span class="style6">*</span> <span class="style7 style3">첨부파일 (File)</span></div></td>
<td>
<input name="upfile" type="file" size="40">
</td>
</tr>
<tr align="right">
<td colspan="2"><div align="right"></div>
<a href="javascript:CheckForm();"><img src="bt_ok.gif" width="70" height="40" border="0"></a><a href="javascript:document.forms.reset();"><img src="bt_cancel.gif" width="70" height="40" border="0"></a>
<div align="center"> </div></td>
</tr>
</table>
</form>
===== PHP파일은 아래와 같습니다. =====
<?
$headers .= "From :$name<$e_mail>rn";
$heasers .= "X-Mailer:PHP MAILERrn";
if($upfile && $upfile_size)
{
$filename=basename($upfile_name);
$result=fopen($upfile,"r");
$file=fread($result,$upfile_size);
fclose($result);
$upfile_type = "application/octet-stream";
$boundary = "--------". uniqid("part");
$headers .= "MIME-Version: 1.0 rn";
$headers .= "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";
$body .= nl2br(stripslashes($contents))."rnrn";
$body .= nl2br(stripslashes($phpworld))."rnrn";
$body .= "--$boundaryrn";
$body .= "Content-Type: $upfile_type; name="$filename"rn";
$body .= "Content-Transfer-Encoding: base64rnrn";
$body .= ereg_replace("(.{80})","\1rn",base64_encode($file));
}
else
{
$body = stripslashes($contents). "rnrn";
}
mail("test@test.com",$subject,$contents,$headers);
echo "<center><br><br><br><br><br><br>
<font color='#cc6600' size='2'>* </font> <font color='#666666'+ '+ ' size='2'> 메일을 발송했습니다 </font> <font color='#cc6600' size='2'>* </font>
</center>";
?>
====== 새해첫날부터 밤새우고 있네요. 도와주세요~
그리고 복많이 받으시구요. ^^;;
잘 안되네요. ㅜ,.ㅜ
저는 왕초보인데 영진책(PHP4_30일완성)보고 따라해 봤슴다.
근데...
파일을 첨부하면 내용글도 전달이 않되고, 첨부파일도 따라가지 않습니다.
파일을 첨부하지 않으면 정상적으로 내용글만 전달됩니다.
==== 메일쓰는 페이지의 폼 부분은 아래와 같구요 ====
<form action="sendmail.php" method="post" name="forms" id="forms" enctype="multipart/form-data">
<br>
<table width="575" border="0" cellspacing="4">
<tr>
<td width="200" valign="bottom"><div align="right" class="style3 style4"><span class="style6">*</span> <span class="style9 style7">성 명 (Name)</span></div></td>
<td width="354">
<input name="name" type="text" class="input" id="name" size="30">
</td>
</tr>
<tr>
<td valign="bottom"><div align="right" class="style5"><span class="style6">*</span> <span class="style7">메 일 (E-mail)</span> </div> <div align="right" class="style5"> </div></td>
<td>
<input name="e_mail" type="text" id="e_mail" size="58">
</td>
</tr>
<tr>
<td valign="bottom"><div align="right" class="style5"><span class="style6">*</span> <span class="style7">제 목 (Subject)</span> </div></td>
<td>
<input name="subject" type="text" id="subject" size="58">
</td>
</tr>
<tr>
<td valign="top"><div align="right" class="style5">
<p><br>
<span class="style6">*</span> <span class="style7">내 용 (Contents)</span> </p>
</div></td>
<td>
<textarea name="contents" cols="57" rows="8" id="contents"></textarea>
</td>
</tr>
<tr>
<td valign="bottom"><div align="right"><span class="style6">*</span> <span class="style7 style3">첨부파일 (File)</span></div></td>
<td>
<input name="upfile" type="file" size="40">
</td>
</tr>
<tr align="right">
<td colspan="2"><div align="right"></div>
<a href="javascript:CheckForm();"><img src="bt_ok.gif" width="70" height="40" border="0"></a><a href="javascript:document.forms.reset();"><img src="bt_cancel.gif" width="70" height="40" border="0"></a>
<div align="center"> </div></td>
</tr>
</table>
</form>
===== PHP파일은 아래와 같습니다. =====
<?
$headers .= "From :$name<$e_mail>rn";
$heasers .= "X-Mailer:PHP MAILERrn";
if($upfile && $upfile_size)
{
$filename=basename($upfile_name);
$result=fopen($upfile,"r");
$file=fread($result,$upfile_size);
fclose($result);
$upfile_type = "application/octet-stream";
$boundary = "--------". uniqid("part");
$headers .= "MIME-Version: 1.0 rn";
$headers .= "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";
$body .= nl2br(stripslashes($contents))."rnrn";
$body .= nl2br(stripslashes($phpworld))."rnrn";
$body .= "--$boundaryrn";
$body .= "Content-Type: $upfile_type; name="$filename"rn";
$body .= "Content-Transfer-Encoding: base64rnrn";
$body .= ereg_replace("(.{80})","\1rn",base64_encode($file));
}
else
{
$body = stripslashes($contents). "rnrn";
}
mail("test@test.com",$subject,$contents,$headers);
echo "<center><br><br><br><br><br><br>
<font color='#cc6600' size='2'>* </font> <font color='#666666'+ '+ ' size='2'> 메일을 발송했습니다 </font> <font color='#cc6600' size='2'>* </font>
</center>";
?>
====== 새해첫날부터 밤새우고 있네요. 도와주세요~
그리고 복많이 받으시구요. ^^;;