/** * ============================================================================= * menu1_1.html - 무료 견적 및 사전 진단 신청서 (#send_mail) * ----------------------------------------------------------------------------- * #send_mail 버튼을 누르면 입력 내용을 모아 ajax/api_mail.php 로 발송합니다. * ============================================================================= */ $(document).ready(function () { 'use strict'; // ========================= // Config & Selectors // ========================= const API_BASE_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api.php`; const API_MAIL_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api_mail.php`; const API_CONTENT_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api_content.php`; const MAIL_TO = 'itfor21@naver.com'; // 문의 메일 수신 주소 (필요 시 변경) const SUBJECT_PREFIX = '[MyPR123:랜딩페이지]'; const $form = $('#send_mail').closest('form'); const $btn = $('#send_mail'); const $btnHtml = $btn.html(); if (!$form.length) { return; } //loadPosts(); // ========================= // Event Binding // ========================= $form.on('submit', onSubmitForm_mail); // ========================= // Handlers // ========================= //send_mail function onSubmitForm_mail(e) { e.preventDefault(); // 실제 전송은 ajax 로 처리 const data = collectData(); if (!data.name) { return alert('회사명 / 담당자 성함을 입력해 주세요.'); } if (!data.phone) { return alert('연락처를 입력해 주세요.'); } if (!data.option) { return alert('희망 패키지를 선택해 주세요.'); } setLoading(true); $.ajax({ url: API_MAIL_URL, type: 'POST', dataType: 'json', data: { to: MAIL_TO, subject: `${SUBJECT_PREFIX} ${data.name} ${data.phone} ${data.option}`.substring(0, 200), message: buildMessage(data), html: false } }).done(function (res) { if (res && res.success) { alert('문의가 정상적으로 접수되었습니다.\n빠른 시일 내에 연락드리겠습니다.'); $form[0].reset(); } else { alert((res && res.message) ? res.message : '메일 발송에 실패했습니다.'); } }).fail(function (xhr) { const res = xhr.responseJSON; alert((res && res.message) ? res.message : '메일 발송 중 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.'); }).always(function () { setLoading(false); }); } // ========================= // Helpers // ========================= function collectData() { return { name: $.trim($('#qa_subject').val() || ''), phone: $.trim($('#qa_phone').val() || ''), option: $.trim($('#qa_option option:selected').text() || ''), etc: $.trim($('#qa_etc').val() || '') }; } function buildMessage(data) { return [ '■ 구분 : 보급형 랜딩페이지', '', `■ 회사명 / 담당자 : ${data.name}`, `■ 연락처 : ${data.phone}`, `■ 희망 패키지 : ${data.option}`, '', '■ 진행 희망 사업 내용 또는 참고 사이트 URL', data.etc || '(내용 없음)', '', '─────────────────────────────', `접수일시 : ${new Date().toLocaleString('ko-KR')}` ].join('\n'); } function setLoading(loading) { $btn.prop('disabled', loading); $btn.html(loading ? ' 발송 중...' : $btnHtml); } // ========================= // List & Detail Logic // ========================= function loadPosts(searchType, searchKeyword, category) { const params = { action: 'detail', board_name: $('#board_name').val(), post_name: $('#post_name').val(), last:'0' }; if (searchKeyword) { params.search_type = searchType || 'title'; params.search_keyword = searchKeyword; } if (category && category !== 'all') { params.category = category; } $.ajax({ url: API_CONTENT_URL, method: 'GET', data: params, dataType: 'json', success(res) { if (!res.success) { alert(res.message || '목록 조회에 실패했습니다.'); return; } $('#my_content').html(res.data.content || ''); }, error: () => alert('목록 조회 중 통신 오류가 발생했습니다.') }); } });