폼메일 첨부파일이 안보내집니다ㅠㅠ
본문
<meta charset="utf-8">
<?php
if(isset($_POST['email'])) {
$email_to = "";
$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['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.');
}
// 첨부파일
function attach_file($upfile, $file) {
$fp = @fopen($file, "r");
$tmpfile = array( "name" => $upfile, "data" => @fread($fp, @filesize($file)));
@fclose($fp);
return $tmpfile;
}
for($i=1, $i<1; $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";
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
// 여기부터 여분내용작업
$category = $_POST['category'];
$etc1 = $_POST['etc1'];
$etc2 = $_POST['etc2'];
$etc3 = $_POST['etc3'];
$etc4 = $_POST['etc4'];
/*$etc5 = $_POST['etc5'];
$etc6 = $_POST['etc6'];
$etc7 = $_POST['etc7'];
$etc8 = $_POST['etc8'];
$etc9 = $_POST['etc9'];*/
$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($name)."<br>";
$email_message .= "연락처 : ".clean_string($telephone)."<br>";
$email_message .= "이메일 : ".clean_string($email_from)."<br>";
$email_message .= "문의내용 : ".clean_string($comments)."<br>";
$email_message .= "주요 취급상품 카테고리: ".clean_string($etc1)."<br>";
$email_message .= "판매 주품목 : ".clean_string($etc2)."<br>";
$email_message .= "원하시는 품목 및 브랜드 : ".clean_string($etc3)."<br>";
$email_message .= "납품사례 및 이력 : ".clean_string($etc4)."<br>";
// create email headers
$headers = "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= 'From: '.$email_from;
// 제목이 깨질경우 아래 캐릭터셋 적용
@mail($email_to, $email_subject, $email_message, $headers, $to_email, $subject, "", $header);
?>
<!-- include your own success html here -->
<script>
alert ("문의주셔서 감사합니다.\n빠른 시일안에 답변드리겠습니다.");
window.location = document.referrer;
</script>
<?php
}
?>
답변을 작성하시기 전에 로그인 해주세요.