폼메일 첨부파일 발송질문
본문
안녕하세요!
폼메일 발송을 동일하게 아래 코드처럼 사용하고있습니다.
<?= nl2br($_POST['content']) ?>
<?php
include "mailer.php";
$mode = $_REQUEST['mode'];
$company_name = $_REQUEST['company_name'];
$name = $_REQUEST['name'];
$wr_1 = $_REQUEST['wr_1'];
$wr_2 = $_REQUEST['wr_2'];
$tel = $_REQUEST['tel'];
$email = $_REQUEST['email'];
$hp = $_REQUEST['hp'];
$code = $_REQUEST['code'];
$client = $_REQUEST['client'];
$title = $_REQUEST['subject'];
$content = $_REQUEST['content'];
$ip = $_SERVER['REMOTE_ADDR'];
$subject = "[폼메일] 입니다.";
$body = "";
$body .= "회사명 : $company_name<br><br>";
$body .= "연락처 : $tel<br><br>";
$body .= "성함 : $name<br><br>";
$body .= "이메일 : $email<br><br>";
$body .= "문의제목 : $title<br>";
$body .= "문의내용 : <br><br>";
$body . "<div style='padding:10px 15px; border:1px solid #dddddd; white-space:pre;'>$content</div>";
$admin_email = "";
if ($mode == "send") {
//파일첨부 시작
for ($i = 1; $i <= 2; $i++) {
$file[$i] = $_FILES['userfile' . $i]['name'];
$target[$i] = "/tmp/" . $file;
if (move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $target[$i])) {
chmod("$target[$i]", 0777);
}
$attach[$i] = attach_file($file[$i], $target[$i]);
//업로드 파일을 삭제한다.
@unlink($target[$i]);
}
//파일첨부 끝
mailer($name, $email, $admin_email, $subject, $body, $type = 1, $attach);
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
echo ("<script>alert('문의하신 내용이 정상적으로 접수되었습니다.');</script>");
echo ("<script>location.href='/'</script>");
}
?>
<form name="form" method="post" enctype="multipart/form-data" class="inquiryCont">
<input type="hidden" name="mode" value="send">
<article class="inquiry_style1 inquiry_tbl_style3">
<h3 class="agree_tit">문의사항</h3>
<table class="write-tbl">
<tbody>
<tr>
<th scope="row">제목</th>
<td>
<input type="text" class="write-input width_100" name="subject" required>
</td>
</tr>
<tr>
<th scope="row">문의내용<span class="essential-icon">*</span> </th>
<td>
<textarea name="content" class="write-textarea" required></textarea>
</td>
</tr>
<tr>
<th scope="row">첨부파일</th>
<td class="filebox">
<div class="file_wr clear">
<label for="file1" class="lb_icon"><span> Attachment</span></label>
<input type="text" class="file-name input1 write-input inquiry_txt" placeholder="Please attach a file."
readonly style="color:#000">
<input type="file" name="userfile1" id="file1" class="frm_file full_input">
<!-- <span class="frm_info">※ 문의 시 이미지를 첨부해 주시면 보다 자세한 상담이 가능 합니다</span> -->
</div>
</td>
</tr>
</tbody>
</table>
</article>
<div class="cm_btn_controls">
<button type="submit" class="btn_submit1">문의하기</button>
</div>
</form>
그리고 mailer.php 내용은 아래와 같습니다.
// type : text=0, html=1, text+html=2
function mailer($from_name, $from_email, $to_email, $subject, $content, $type=1, $file="") {
$conf['charset'] = "utf-8";
$from_name = "=?$conf[charset]?B?" . base64_encode($from_name) . "?=";
$subject = "=?$conf[charset]?B?" . base64_encode($subject) . "?=";
$header = "Return-Path: <$from_email>\n";
$header .= "From: $from_name <$from_email>\n";
$header .= "Reply-To: <$from_email>\n";
$header .= "MIME-Version: 1.0\n";
if ($file != "") {
$boundary = uniqid("http://localhost");
$header .= "Content-type: MULTIPART/MIXED; BOUNDARY=\"$boundary\"\n\n";
$header .= "--$boundary\n";
}
if ($type) {
$header .= "Content-Type: TEXT/HTML; charset=$conf[charset]\n";
if ($type == 2) $content = nl2br($content);
} else {
$header .= "Content-Type: TEXT/PLAIN; charset=$conf[charset]\n";
$content = stripslashes($content);
}
$header .= "Content-Transfer-Encoding: BASE64\n\n";
$header .= chunk_split(base64_encode($content)) . "\n";
for($i=1;$i<=3;$i++) {
if($file[$i]['name'] == '') continue;
$file_name = $file[$i]['name'];
$header .= "\n--$boundary\n";
$header .= "Content-Type: application/octet-stream\n";
$header .= "Content-Transfer-Encoding: BASE64\n";
$header .= "Content-Disposition: attachment; filename=\"$file_name\"\n";
$header .= "\n";
$header .= base64_encode($file[$i]['data']);
$header .= "\n";
}
$header .= "--$boundary--\n\n";
//1번.
//@mail($to_email, $subject, "", $header);
//서버 환경에 따라서 아래처럼 옵션값을 넣어줘야 발송이 되는 호스팅이 있습니다.
//1번으로 발송이 안 될 경우 2번처럼 해보세요.(1번 주석처리, 2번 주석 제거)
//2번.
@mail($to_email, $subject, "", $header,'-f'.$from_email);
}
// 파일을 첨부함
function attach_file($file_name, $file) {
$fp = @fopen($file, "r");
$tmpfile = array(
"name" => $file_name,
"data" => @fread($fp, @filesize($file)));
@fclose($fp);
return $tmpfile;
}
?>
기존에 계속 cafe24.com으로 위내용으로 작업을 했을때는 첨부파일이 메일로 잘 들어왔었는데요
최근에 mycafe24.com으로 도메인을 변경한 뒤로부터는 다른내용은 메일 발송이 잘되는데
첨부파일이 들어오지않습니다...
정말 어떠한 방법을해도 들어오질않네요ㅠㅠ
확인해주시고 답변 부탁드립니다!! 꼭이요!!! 감사합니다!!!