메일폼 제작했는데, 첨부파일이 안됩니다 ㅠ 채택완료
qoqofh
4년 전
조회 3,360
html 코드는 이렇고,
</p>
<p><form name="formmail" method="get" action="consulting.php" onSubmit="return chkMailFrm()" id="form">
<input type="text" name="name" placeholder="이름 또는 기업명" class="input_name">
<input type="text" name="tell" placeholder="연락처" class="input_tell">
<input type="text" name="email" placeholder="이메일" class="input_email">
<input type="text" name="address" placeholder="희망지역" class="input_address">
<textarea name="area" id="area" placeholder="간단소개(생략가능)" cols="30" rows="10" class="input_area"></textarea>
<input type="file" name="upfile" size="50">
<button type="submit" class="submit_btn" name="submit" id="submit">보내기</button>
</form></p>
<p>
php코드는 이렇습니다.
</p>
<p><?
//보내는 이
$recipient = "email.naver.com";
//제목 처리
$subject = '=?UTF-8?B?'.'?=제목입니다.';
//메일주소
$mail_from = '=?UTF-8?B?'.base64_encode($_GET['email']).'?=';</p>
<p>
// --- 첨부화일이 있을경우 --- //
if($upfile && $upfile_size) {
$filename=basename($upfile_name); // 파일명 추출
$fp = fopen($upfile,"r"); // 파일 열기
$file = fread($fp,$upfile_size); // 파일 읽기
fclose($fp); // 파일 닫기
if ($upfile_type == ""){
$upfile_type = "application/octet-stream";
}
//메일내용
$mail_body = "<table width='1100' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td width='200' height='30' align='center' bgcolor='#eeeeee'>이름 또는 기업명</td>
<td width='900' bgcolor='#FFFFFF'>". $_GET['name']."</td></tr>".
" <tr>
<td width='200' height='30' align='center' bgcolor='#eeeeee'>연락처</td>
<td width='900' bgcolor='#FFFFFF'>". $_GET['tell']."</td></tr>".
" <tr>
<td width='200' height='30' align='center' bgcolor='#eeeeee'>이메일</td>
<td width='900' bgcolor='#FFFFFF'>". $_GET['email']."</td></tr>".
" <tr>
<td width='200' height='30' align='center' bgcolor='#eeeeee'>희망지역</td>
<td width='900' bgcolor='#FFFFFF'>". $_GET['address']."</td></tr>". </p>
<p> " <tr>
<td width='200' height='30' align='center' bgcolor='#eeeeee'>간단설명</td>
<td width='900' bgcolor='#FFFFFF'>". $_GET['area']."</td></tr>". </p>
<p>
"</table>";</p>
<p>//메일 발송처리</p>
<p> $header = "From:$subject\n";
$header = "Content-Type: text/html;charset=UTF-8";
$header .= "From : $mail_from <".$mail_from.">\n"; </p>
<p>
$email = mail($recipient, $subject, $mail_body, $header);</p>
<p> if (!$email)
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <script>
window.alert('메일 발송이 실패하였습니다. ');
history.go(-1);
</script>";
else
echo " <script>
window.alert('메일이 정상적으로 발송되었습니다.');
history.go(-1);
</script>";
?></p>
<p>
근데 뭐가 잘못됬는지.... 첨부파일이 첨부가 되도 첨부되어있지않은상태에서 메일이 오는데 어디가 문제일까요 ㅠㅠ?
댓글을 작성하려면 로그인이 필요합니다.
답변 2개
답변을 작성하려면 로그인이 필요합니다.
로그인
지금 여기에는 첨부파일 코드는 삽입되어있지 않은데, php에 삽입하려고하면 어떻게 넣어야할지 해서요 ㅠ
php
[code]
<meta charset="utf-8">
<?php
if(isset($_POST['email'])) {
$email_to = "emaiol@naver.com";
$email_subject = "제목";
$email_subject = '=?UTF-8?B?'.base64_encode($email_subject).'?=';
function died($error) {
// your error code can go here
echo "<script> alert('메일발송을 실패하였습니다. 항목을 다시한번확인해 주세요.');";
echo "history.go(-1);";
echo "</script>";
die();
}
// validation expected data exists
if(!isset($_POST["catego"]) ||
!isset($_POST['com_name']) ||
!isset($_POST['email']) ||
!isset($_POST['address']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$catego = implode(" / ",$_POST["catego"]);
//$sangpum = $_POST['sangpum'];
$com_name = $_POST['com_name']; // required
$email_from = $_POST['email']; // required
$address_from = $_POST['address']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
//if(strlen($comments) < 2) {
// $error_message .= 'The Comments you entered do not appear to be valid.<br />';
//}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "문의 선택 : ".clean_string($catego)."\n\n";
$email_message .= "이름 또는 기업명 : ".clean_string($com_name)."\n\n";
$email_message .= "연락처 : ".clean_string($telephone)."\n\n";
$email_message .= "이메일 : ".clean_string($email_from)."\n\n";
$email_message .= "주소 : ".clean_string($address_from)."\n\n";
$email_message .= "소개내용 : ".clean_string($comments)."\n\n";
// create email headers
$headers = 'From: '.$email_from;
// 제목이 깨질경우 아래 캐릭터셋 적용
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<script>
alert ("메일이 발송되었습니다.\n빠른 시일안에 답변드리겠습니다.");
location.href='http://i-kit.kr/i-kit_consulting.html';
</script>
<?php
}
?>
[/code]
html
[code]
<form name="contactform" method="post" action="./send.php">
<table>
<tr class="true_chk">
<th scope="row">
<label for="catego" class="form_tit">문의 항목 선택</label></th>
<td class="">
<label class="check_box_la" style="display: inline-table; margin-bottom:5px; margin: 20px;"><input type="checkbox" name="catego[]" value="지사 문의" class="radio_box">지사 문의</label>
<label class="check_box_la" style="display: inline-table; margin-bottom:5px;"><input type="checkbox" name="catego[]" value="판매처 문의" class="radio_box">판매처 문의</label>
</td>
</tr>
</table>
<input name="com_name" type="text" class="ipt int input_name" size="30" maxlength="50" placeholder="이름 또는 기업명" required >
<input name="telephone" type="text" class="ipt int input_tell" size="30" maxlength="30" placeholder="연락처" required >
<input name="email" type="text" class="ipt int input_email" size="30" maxlength="80" placeholder="이메일" required >
<input name="address" type="text" class="ipt int input_address" size="30" maxlength="80" placeholder="개설지역" required >
<textarea name="comments" cols="50" class="tx_area int input_area" rows="5" placeholder="간단한 소개내용 또는 문의사항을 적어주세요." value=""></textarea>
<input type="submit" value="보내기" class="btn_submit submit_btn">
</form>
[/code]