폼메일에서 메일로 파일전송하기
본문
https://sir.kr/g5_skin/10486 이 스킨 기준으로 적용중입니다.
이메일로 다른 text 내용들은 잘 전달 되는데 첨부파일이 안넘어가네요.. 기존 그누보드 파일 참고해도 뭘 건드려야할지 모르겠습니다 ㅠㅠ.
html
<div class="form_wrapper">
<div class="close_btn_form"><img src="<?php echo G5_IMG_URL?>/icon_close.png"></div>
<p class="email_tit">홍익이엔지<br>메일작성</p>
<div class="line_email"></div>
<form name="contactform" method="post" action="send.php" enctype="multipart/form-data">
<table>
<tr>
<th scope="row">
<label for="first_name">이름</label></th>
<td width="80%">
<input name="first_name" type="text" class="ipt" style="height:40px" size="30" maxlength="50" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="email">이메일 주소</label></th>
<td>
<input name="email" type="text" class="ipt" style="height:40px" size="30" maxlength="80" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="telephone">연락처</label></th>
<td>
<input name="telephone" type="text" class="ipt" style="height:40px" size="30" maxlength="30" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="comments">문의내용</label></th>
<td height="170" valign="bottom">
<textarea name="comments" cols="50" rows="10" style="width:95%" required ></textarea></td>
</tr>
<p class="file_in">
<span class="flie_txt">파일첨부</span>
<label for="file1" class="lb_icon"><i class="fa fa-download" aria-hidden="true"></i><span class="sound_only"> 첨부 파일 1</span></label>
<input type="file" name="file1" id="file1" class="frm_file full_input">
</p>
<tr>
<td height="40" colspan="2" style="text-align:center">
<input type="submit" value="전송하기" class="btn_submit">
<input name="재설정" type="reset" value="다시작성" class="btn_submit"></td>
</tr>
</table>
</form>
</div>
폼스킨의 send.php
<meta charset="utf-8">
<?php
if(isset($_POST['email'])) {
$email_to = "이메일@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['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$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($first_name)."\n\n";
$email_message .= "이메일 : ".clean_string($email_from)."\n\n";
$email_message .= "연락처 : ".clean_string($telephone)."\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='../';
</script>
<?php
}
?>
답변을 작성하시기 전에 로그인 해주세요.