PHP로 작성된 폼을 이메일로 전송하는 프로그램
최근 웹사이트를 개편하면서 온라인 폼을 이메일로 전송하는 프로그램을 만들고 싶었는데, 여러 가지를 찾아봤지만 다 쓸 수 없어서 결국 직접 만들었습니다.
<html><body><?phpfunction spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } }
if (isset($_REQUEST['w_14'])) {//if "email" is filled out, proceed
//check if the email address is invalid $mailcheck = spamcheck($_REQUEST['w_14']); $w_1_check = $_REQUEST['w_1']; $w_8_check = $_REQUEST['w_8']; $w_13_check = $_REQUEST['w_13']; if ($mailcheck==FALSE) { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"이메일을 정확히 입력해 주시기 바랍니다. 담당자가 연락드릴 수 있도록 협조 부탁드립니다. 감사합니다!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_1_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"회사명을 정확히 입력해 주시기 바랍니다. 담당자가 연락드릴 수 있도록 협조 부탁드립니다. 감사합니다!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_8_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"성함을 정확히 입력해 주시기 바랍니다. 담당자가 연락드릴 수 있도록 협조 부탁드립니다. 감사합니다!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } if ($w_13_check=='') { echo "<script language=\"JavaScript\">\r\n"; echo " alert(\"QQ/MSN 번호를 정확히 입력해 주시기 바랍니다. 담당자가 연락드릴 수 있도록 협조 부탁드립니다. 감사합니다!\");\r\n"; echo " history.back();\r\n"; echo "</script>"; } else {//send email $email = $_REQUEST['w_14'] ; $subject = $_REQUEST['w_1'] . " " . $_REQUEST['w_8'] ; $message = "회사명 :". $_REQUEST['w_1'] . "\r\n" . "웹 페이지 언어 :". $_REQUEST['w_2_1'] . "/" . $_REQUEST['w_2_2'] . "/" . $_REQUEST['w_2_3'] . "/" . $_REQUEST['w_2_4'] . "/" . $_REQUEST['w_2_5'] . "/" . "\r\n" . "참고하고 싶은 사이트 :". $_REQUEST['w_3'] . "\r\n" . "주요 비즈니스 소개 :". $_REQUEST['w_4'] . "\r\n" . "웹사이트 제작 예산 :". $_REQUEST['w_5'] . "-" . $_REQUEST['w_6'] . "\r\n" . "요청 완료 시간 :". "완료 희망 날짜" . $_REQUEST['w_7'] . "\r\n" . " 완료 희망 일수" . $_REQUEST['w_7_1'] . "\r\n" . "웹사이트 제작 기타 요구사항 :". $_REQUEST['w_7_2'] . "\r\n" . "=============================================================" . "\r\n" . "성함 :". $_REQUEST['w_8'] . "\r\n" . "성별 :". $_REQUEST['w_9'] . "\r\n" . "전화 :". $_REQUEST['w_11'] . "\r\n" . "휴대폰 :". $_REQUEST['w_12'] . "\r\n" . "QQ/MSN :". $_REQUEST['w_13'] . "\r\n" . "이메일 :". $_REQUEST['w_14'] . "\r\n" . "Skype :". $_REQUEST['w_15'] . "\r\n" . "우편번호 :". $_REQUEST['w_16'] . "\r\n" . "상세 주소 :". $_REQUEST['w_17'] . "\r\n"; mail("admin@zhaojian.net", "$subject 작성한 웹사이트 제작 의향서.", $message, "From: $email"); echo "<script language=\"JavaScript\">\r\n"; echo "alert(\"정보 제출 완료! 담당자가 연락드릴 때까지 기다려 주세요. 자동으로 홈페이지로 돌아갑니다.\");\r\n"; echo "location.replace(\"http://www.zhaojian.net/\");\r\n"; echo "</script>"; } }else {//if "email" is not filled out, display the form echo "<form id='form1' action='http://www.zhaojian.net/b/b.php' method='post' name='form1'> <table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <th colspan='2'>웹사이트 제작 신청서</th> </tr> <tr> <td class='input_1' width='125'>회사명</td> <td class='input_2' width='550'><input class='input_text' style='width: 300px' name='w_1' type='text' /></td> </tr> <tr> <td class='input_1' width='125'>웹 페이지 언어</td> <td class='input_2' width='550'><input type='checkbox' checked='checked' name='w_2_1' value='중국어 간체' /> <label for='w_2_1'>중국어 간체</label> <input type='checkbox' name='w_2_2' value='중국어 번체' /> <label for='w_2_2'>중국어 번체</label> <input type='checkbox' name='w_2_3' value='영어' /> <label for='w_2_3'>영어</label> <input type='checkbox' name='w_2_4' value='일본어' /> <label for='w_2_4'>일본어</label> <input type='checkbox' name='w_2_5' value='기타 언어' /> <label for='w_2_5'>기타 언어</label></td> </tr> <tr> <td class='input_1' width='125'>참고하고 싶은 사이트</td> <td class='input_2' width='550'><input style='width: 300px' name='w_3' type='text' /></td> </tr> <tr> <td class='input_1' width='125'>주요 비즈니스 소개</td> <td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_4'></textarea></td> </tr> <tr> <td class='input_1' width='125'>웹사이트 제작 예산</td> <td class='input_2' width='550'><input class='input_text' name='w_5' type='text' /> -- <input class='input_text' name='w_6' type='text' /> 위안</td> </tr> <tr> <td class='input_1' width='125'>요청 완료 시간</td> <td class='input_2' width='550'><input class='input_text' name='w_7' value='완료 희망 날짜' type='text' /> <input class='input_text' name='w_7_1' value='완료 희망 일수' type='text' /> 일</td> </tr> <tr> <td class='input_1' width='125'>웹사이트 제작 기타 요구사항</td> <td class='input_2' width='550'><textarea class='input_text' style='width: 300px' name='w_7_2'></textarea></td> </tr> </tbody> </table> <table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <th colspan='4'>연락처 정보</th> </tr> <tr> <td class='input_1' width='129'>성함</td> <td class='input_2' width='202'><input name='w_8' type='text' /></td> <td class='input_1' width='96'>성별</td> <td class='input_2' width='246'><input type='radio' checked='checked' name='w_9' value='여성' />여성 <input type='radio' name='w_9' value='남성' />남성</td> </tr> <tr> <td class='input_1' align='left'>전화</td> <td class='input_2'><input class='input_text' name='w_11' type='text' /></td> <td class='input_1'>휴대폰</td> <td class='input_2'><input name='w_12' type='text' /></td> </tr> <tr> <td class='input_1'>QQ / MSN</td> <td class='input_2'><input class='input_text' name='w_13' type='text' /></td> <td class='input_1'>이메일</td> <td class='input_2'><input name='w_14' type='text' /></td> </tr> <tr> <td class='input_1'>Skype</td> <td class='input_2'><input class='input_text' name='w_15' type='text' /></td> <td class='input_1'>우편번호</td> <td class='input_2'><input name='w_16' type='text' /></td> </tr> <tr> <td class='input_1'>상세 주소</td> <td class='input_2'><input name='w_17' type='text' /></td> <td class='input_1'>회사 주소</td> <td class='input_2'><input name='w_172' type='text' /></td> </tr> </tbody> </table>
<table class='table_1' cellspacing='0' cellpadding='0' width='675' border='0'> <tbody> <tr> <td class='input_2'> <div align='center'><input id='send_mail_agent' type='submit' name='w_18' value='Submit' /></div> </td> </tr> </tbody> </table> </form>"; }?>
</body></html>