메일보내기 첨부파일, 여러내용 채택완료
submit 클릭 시 메일보내지는 형식으로 구축하려하는데
지금 메일전송까지는 되는데 첨부파일전송이 안되고
메일 내용에 name="m_txt" 이외에 name="u_name" 등 여러가지 내용을 보내고 싶습니다.
html
</strong><form method="post" action="sub0601_update.php" enctype="multipart/form-data" onsubmit="return mail_proc(this);" name="gogo"></p>
<p> <ul></p>
<p> <li style="display:none"></p>
<p> <div width="110" align="left"></div></p>
<p> <div align="left"><input type="text" name="femail" style="width:658px;" value="kindad@naver.com" /></div></p>
<p></li></p>
<p> <li style="display:none"></p>
<p> <div width="110" align="left"></div></p>
<p> <div align="left"><input type="text" name="temail" style="width:658px;" value="kindad@naver.com" /></div></p>
<p></li></p>
<p> <li class="lb01 h30"></p>
<p> <label for="tit">현장명 (field name)</label></p>
<p> <input type="text" id="tit" name="tit" required /></p>
<p> </li></p>
<p> <li class="lb02 h30"></p>
<p> <label for="s_date">접수일자 (reception date)</label></p>
<p> <input type="text" id="s_date" name="s_date" required class="datepicker" /></p>
<p> </li></p>
<p> <li class="lb03 h30"></p>
<p> <label for="add">신청지 주소 (order address)</label></p>
<p> <input type="text" id="add" name="add" required /></p>
<p> </li></p>
<p> <li class="lb04 h30"></p>
<p> <label for="u_name">신청인 성명 (subscriber name)</label></p>
<p> <input type="text" id="u_name" name="u_name" required /></p>
<p> </li></p>
<p> <li class="lb05 h30"></p>
<p> <label for="u_tel">신청인 전화번호 (subscriber phone number)</label></p>
<p> <input type="tel" id="u_tel" name="u_tel" required /></p>
<p> </li></p>
<p> <li class="lb06 h30"></p>
<p> <label for="b_date">준공일 (completion date)</label></p>
<p> <input type="text" id="b_date" name="b_date" class="datepicker" /></p>
<p> </li></p>
<p> <li class="lb07"></p>
<p> <label for="m_txt">하자내용 (defect content)</label></p>
<p> <textarea name="m_txt" id="m_txt" cols="30" rows="10" required style=" vertical-align:middle; line-height: 20px; "></textarea></p>
<p> </li></p>
<p> <li class="lb08 h30"></p>
<p> <label for="u_pw">비밀번호 (password)</label></p>
<p> <input type="text" id="u_pw" name="u_pw" required /></p>
<p> </li></p>
<p> <li class="lb09 h30"></p>
<p> <p>첨부파일 (attached file)</p></p>
<p> <input type="file" id="u_file" name="u_file" /></p>
<p> </li></p>
<p> </ul></p>
<p> </p>
<p> <div class="submit"></p>
<p> <input type="submit" value="제출 (submission)" onclick="return mail_proc(this.form);" /></p>
<p> </div></p>
<p> </form><strong>
.php
</strong></p>
<p>$femail = $_POST['femail'];</p>
<p>$temail = $_POST['temail'];</p>
<p>$remail = $_POST['remail'];</p>
<p>$hemail = $_POST['hemail'];</p>
<p>$subject = $_POST['tit'];</p>
<p>$message = $_POST['m_txt'];</p>
<p> </p>
<p>$boundary = "----" . uniqid("part"); // 구분자</p>
<p> </p>
<p>// --- 헤더 --- //</p>
<p>$headers = "Return-Path: ".str_replace("\\", "", $femail)."\r\n";</p>
<p>$headers .= "From: ".str_replace("\\", "", $femail)."\r\n";</p>
<p>if($remail) {</p>
<p> $headers .= "Cc: ".str_replace("\\", "", $remail)."\r\n";</p>
<p>}</p>
<p>if($hemail) {</p>
<p> $headers .= "Bcc: ".str_replace("\\", "", $hemail)."\r\n";</p>
<p>}</p>
<p> </p>
<p>if($attach_url && $attach_name) { // --- 첨부파일 --- //</p>
<p> $filename=$attach_name;</p>
<p> $fp = fopen($attach_url,"r");</p>
<p> $file = fread($fp,$attach_size);</p>
<p> fclose($fp);</p>
<p> if ($attach_type == ""){</p>
<p> $attach_type = "application/octet-stream";</p>
<p> }</p>
<p> // --- 헤더 --- //</p>
<p> $headers .= "MIME-Version: 1.0\r\n";</p>
<p> $headers .= "Content-Type: Multipart/mixed; boundary=\"$boundary\"";</p>
<p> // --- 본문 --- // </p>
<p> $mailbody = "This is a multi-part message in MIME format.\r\n\r\n";</p>
<p> $mailbody .= "--$boundary\r\n";</p>
<p> $mailbody .= "Content-Type: text/html; charset=utf-8\r\n";</p>
<p> $mailbody .= "Content-Transfer-Encoding: base64\r\n\r\n";</p>
<p> $mailbody .= chunk_split(base64_encode(str_replace("\\", "", $message))) . "\r\n";</p>
<p> // --- 첨부 --- // </p>
<p> $mailbody .= "--$boundary\r\n"; </p>
<p> $mailbody .= "Content-Type: ".$attach_type."; name=\"".$filename."\"\r\n";</p>
<p> $mailbody .= "Content-Transfer-Encoding: base64\r\n";</p>
<p> $mailbody .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";</p>
<p> $mailbody .= base64_encode($file)."\r\n\r\n";</p>
<p> $mailbody .= "--$boundary--";</p>
<p>}</p>
<p>else {</p>
<p> // --- 헤더 --- // </p>
<p> $headers .= "MIME-Version: 1.0\r\n"; </p>
<p> $headers .= "Content-Type: Multipart/alternative; boundary = \"$boundary\"";</p>
<p> // --- 본문 --- //</p>
<p> $mailbody = "--$boundary\r\n"; </p>
<p> $mailbody .= "Content-Type: text/html; charset=utf-8\r\n";</p>
<p> $mailbody .= "Content-Transfer-Encoding: base64\r\n\r\n";</p>
<p> $mailbody .= chunk_split(base64_encode(str_replace("\\", "", $message))) . "\r\n";</p>
<p> $mailbody .= "--$boundary--\r\n\r\n"; </p>
<p>}</p>
<p> </p>
<p>$ret = mail($temail, $subject, $mailbody, $headers);</p>
<p> </p>
<p>if(!$tit || !$u_name|| !$u_tel){</p>
<p> alert('잘못된 접근입니다.');</p>
<p> exit;</p>
<p>}</p>
<p> </p>
<p>$file = "";</p>
<p> </p>
<p><strong>
답변 3개
php 상단에
$u_name= $_POST['u_name']; 추가해주시고
$attach_url = $_FILES['u_file']['tmp_name'];
$attach_name = $_FILES['u_file']['name'];
36번째줄에 어떤방식으로 u_name을 넣으실껀지 모르겠지만 만약 body 젤상단에 넣으실꺼면
$mailbody .= chunk_split(base64_encode(str_replace("\\", "", $u_name."\r\n".$message))) . "\r\n";
이런식으로 바꾸면되지않을까요
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
1. m_txt 입력란에 보내실 내용을 모두 작성하는 방법이 있구요.
2. 전송하는 파일에서 $message 변수에 원하시는 값을 추가해줘야 합니다.
예) $message = "신청인명 : $u_name ".$message;
첨부파일은 아래 링크 참조하세요.
댓글을 작성하려면 로그인이 필요합니다.
1. m_txt 입력란에 보내실 내용을 모두 작성하는 방법이 있구요.
2. 전송하는 파일에서 $message 변수에 원하시는 값을 추가해줘야 합니다.
예) $message = "신청인명 : $u_name ".$message;
첨부파일은 아래 링크 참조하세요.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인