//btn_idex_sendmail 버튼 클릭시 idx_onSubmitForm 함수 호출 $('#btn_idex_sendmail').on('click', idx_onSubmitForm); const $btn = $('#btn_idex_sendmail'); const $form = $('#quoteForm').closest('form'); const $btnHtml = $btn.html(); let sending = false; // 중복 발송 방지 // ========================= // Handlers // ========================= function idx_onSubmitForm(e) { e.preventDefault(); // 실제 전송은 ajax 로 처리 const API_MAIL_URL = `${typeof hostURL !== 'undefined' ? hostURL : ''}/ajax/api_mail.php`; const MAIL_TO = 'itfor21@naver.com'; // 문의 메일 수신 주소 (필요 시 변경) const SUBJECT_PREFIX = '[MyPR123:견적요청]'; if (sending) { return; } const data = idx_collectData(); if (!data.company) { return alert('회사명을 입력해 주세요.'); } if (!data.name) { return alert('담당자 성함을 입력해 주세요.'); } if (!data.phone) { return alert('연락처를 입력해 주세요.'); } if (!data.industry) { return alert('산업군을 입력해 주세요.'); } if (!data.budget) { return alert('예산을 입력해 주세요.'); } if (!data.services) { return alert('희망 서비스를 선택해 주세요.'); } if(!$('#privacyCheck').prop('checked')){ return alert('개인정보 수집 및 상담 목적의 이용에 동의해 주세요.'); } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) { return alert('이메일 주소를 정확히 입력해 주세요.'); } idx_setLoading(true); $.ajax({ url: API_MAIL_URL, type: 'POST', dataType: 'json', data: { to: MAIL_TO, subject: `${SUBJECT_PREFIX} ${data.company} ${data.phone} ${data.industry} ${data.services}`.substring(0, 200), message: idx_buildMessage(data), replyTo: data.email, html: false } }).done(function (res) { if (res && res.success) { alert('상담 신청이 정상적으로 접수되었습니다.\n영업일 기준 24시간 이내에 연락드리겠습니다.'); $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 () { idx_setLoading(false); }); } // ========================= // Helpers // ========================= function idx_collectData() { return { company: $.trim($('#company').val() || ''), industry: $.trim($('#industry').val() || ''), budget: $.trim($('#budget').val() || ''), services: $.trim($('input[name="services"]:checked').map(function() { return this.value; }).get().join(', ') || ''), name: $.trim($('#name').val() || ''), phone: $.trim($('#phone').val() || ''), email: $.trim($('#email').val() || ''), content: $.trim($('#detail').val() || '') }; } function idx_buildMessage(data) { return [ '■ 구분 : 종합 견적 문의', '', `회사명 : ${data.company}`, `산업군 : ${data.industry}`, `예산 : ${data.budget}`, `희망 서비스 : ${data.services}`, `담당자 : ${data.name}`, `연락처 : ${data.phone}`, `이메일 : ${data.email}`, '', '■ 프로젝트 개요 및 문의사항', data.content || '(내용 없음)', '', '─────────────────────────────', `접수일시 : ${new Date().toLocaleString('ko-KR')}` ].join('\n'); } function idx_setLoading(loading) { sending = loading; $btn.prop('disabled', loading); $btn.html(loading ? ' 발송 중...' : $btnHtml); }