Отправка формы на почту

Здравствуйте. Делаю сайт по шаблону, впервые столкнулась с JavaScript и нахожусь в недоумении :)

Нужно настроить отправку формы на сайт, есть такой скрипт:

return a?void(b&&(c=document.createElement(“style”),c.type=“text/css”,c.styleSheet?c.styleSheet.cssText=b:c.appendChild(document.createTextNode(b)),a.appendChild©)):!1}},{}],15:[function(a,b){“use strict”;var c={AED:{before:“ج”},ANG:{before:“ƒ”},ARS:{before:"$",code:!0},AUD:{before:"$",code:!0},AWG:{before:“ƒ”},BBD:{before:"$",code:!0},BGN:{before:“лв”},BMD:{before:"$",code:!0},BND:{before:"$",code:!0},BRL:{before:“R$”},BSD:{before:"$",code:!0},CAD:{before:"$",code:!0},CHF:{before:"",code:!0},CLP:{before:"$",code:!0},CNY:{before:“¥”},COP:{before:"$",code:!0},CRC:{before:“₡”},CZK:{before:“Kc”},DKK:{before:“kr”},DOP:{before:"$",code:!0},EEK:{before:“kr”},EUR:{before:“€”},GBP:{before:“£”},GTQ:{before:“Q”},HKD:{before:"$",code:!0},HRK:{before:“kn”},HUF:{before:“Ft”},IDR:{before:“Rp”},ILS:{before:“₪”},INR:{before:“Rs.”},ISK:{before:“kr”},JMD:{before:“J$”},JPY:{before:“¥”},KRW:{before:“₩”},KYD:{before:"$",code:!0},LTL:{before:“Lt”},LVL:{before:“Ls”},MXN:{before:"$",code:!0},MYR:{before:“RM”},NOK:{before:“kr”},NZD:{before:"$",code:!0},PEN:{before:“S/”},PHP:{before:“Php”},PLN:{before:“z”},QAR:{before:“﷼”},RON:{before:“lei”},RUB:{before:“руб”},SAR:{before:“﷼”},SEK:{before:“kr”},SGD:{before:"$",code:!0},THB:{before:“฿”},TRY:{before:“TL”},TTD:{before:“TT$”},TWD:{before:“NT$”},UAH:{before:“₴”},USD:{before:"$",code:!0},UYU:{before:"$U"},VEF:{before:“Bs”},VND:{before:“₫”},XCD:{before:"$",code:!0},ZAR:{before:“R”}};b.exports=function(a,b){var d=b&&b.currency||“USD”,e=c[d],f=e.before||"",g=e.after||"",h=e.length||2,i=e.code&&b&&b.showCode,j=a;return b&&b.format&&(j=f+j.toFixed(h)+g),i&&(j+=" “+d),j}},{}],16:[function(a,b){“use strict”;b.exports=function(a,b){var c=[];return b?b.addEventListener?{add:function(a,b,d,e){e=e||a;var f=function(a){d.call(e,a)};a.addEventListener(b,f,!1),c.push([a,b,d,f])},remove:function(a,b,d){var e,f,g,h=c.length;for(g=0;h>g;g++)if(f=c[g],f[0]===a&&f[1]===b&&f[2]===d&&(e=f[3]))return a.removeEventListener(b,e,!1),c=c.slice(g),!0}}:b.attachEvent?{add:function(b,d,e,f){f=f||b;var g=function(){var b=a.event;b.target=b.target||b.srcElement,b.preventDefault=function(){b.returnValue=!1},e.call(f,b)};b.attachEvent(“on”+d,g),c.push([b,d,e,g])},remove:function(a,b,d){var e,f,g,h=c.length;for(g=0;h>g;g++)if(f=c[g],f[0]===a&&f[1]===b&&f[2]===d&&(e=f[3]))return a.detachEvent(“on”+b,e),c=c.slice(g),!0}}:void 0:{add:function(){},remove:function(){}}}(“undefined”==typeof window?null:window,“undefined”==typeof document?null:document)},{}],17:[function(a,b){“use strict”;var c=b.exports={parse:function(a){var b,d,e,f,g=a.elements,h={};for(e=0,f=g.length;f>e;e++)b=g[e],(d=c.getInputValue(b))&&(h[b.name]=d);return h},getInputValue:function(a){var b=a.tagName.toLowerCase();return"select”===b?a.options[a.selectedIndex].value:“textarea”===b?a.innerText:“radio”===a.type?a.checked?a.value:null:“checkbox”===a.type?a.checked?a.value:null:a.value}}},{}],18:[function(a,b){“use strict”;b.exports=function c(a,b){var d;for(var e in b)d=b[e],d&&d.constructor===Object&&a[e]?c(a[e]||{},d):a[e]=d;return a}},{}],19:[function(a,b){“use strict”;function c(){this._eventCache={}}c.prototype.on=function(a,b,c){var d=this._eventCache[a];d||(d=this._eventCache[a]=[]),d.push([b,c])},c.prototype.off=function(a,b){var c,d,e=this._eventCache[a];if(e)for(c=0,d=e.length;d>c;c++)e[c]===b&&(e=e.splice(c,1))},c.prototype.fire=function(a){var b,c,d,e,f=this._eventCache[a];if(f)for(b=0,c=f.length;c>b;b++)d=f[b][0],e=f[b][1]||this,“function”==typeof d&&d.apply(e,Array.prototype.slice.call(arguments,1))},b.exports=c},{}],20:[function(a,b){“use strict”;var c=b.exports=function(a,b){this._name=a,this._duration=b||30},d=c.prototype;d.load=function(){if(“object”==typeof window&&window.localStorage){var a,b,c=window.localStorage.getItem(this._name);return c&&(c=JSON.parse(decodeURIComponent©)),c&&c.expires&&(a=new Date,b=new Date(c.expires),a>b)?void this.destroy():c&&c.value}},d.save=function(a){if(“object”==typeof window&&window.localStorage){var b,c=new Date;c.setTime(c.getTime()+24this._duration60601e3),b={value:a,expires:c.toGMTString()},window.localStorage.setItem(this._name,encodeURIComponent(JSON.stringify(b)))}},d.destroy=function(){“object”==typeof window&&window.localStorage&&window.localStorage.removeItem(this._name)}},{}],21:[function(a,b){“use strict”;var c=a(“ejs”);b.exports=function(a,b){return c.render(a,b)},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")})},{ejs:6}],22:[function(a,b){“use strict”;function c(a){var b;this.el=b=document.createElement(“div”),this.model=a,this.isShowing=!1,b.id=d.name,d.parent.appendChild(b),h.inject(document.getElementsByTagName(“head”)[0],d.styles),e.add(document,“ontouchstart"in window?“touchstart”:“click”,i.click,this),e.add(document,“keyup”,i.keyup,this),e.add(document,“readystatechange”,i.readystatechange,this),e.add(window,“pageshow”,i.pageshow,this)}var d=a(”./config"),e=a("./util/events"),f=a("./util/template"),g=a("./util/forms"),h=a("./util/css"),i=a("./viewevents"),j=a("./constants");c.prototype.redraw=function(){e.remove(this.el.querySelector(“form”),“submit”,this.model.cart.checkout,this.model.cart),this.el.innerHTML=f(d.template,this.model),e.add(this.el.querySelector(“form”),“submit”,this.model.cart.checkout,this.model.cart)},c.prototype.show=function(){this.isShowing||(h.add(document.body,j.SHOWING_CLASS),this.isShowing=!0)},c.prototype.hide=function(){this.isShowing&&(h.remove(document.body,j.SHOWING_CLASS),this.isShowing=!1)},c.prototype.toggle=function(){thisthis.isShowing?“hide”:“show”},c.prototype.bind=function(a){var b=this;return j.COMMANDS[a.cmd.value]?a.hasMinicart?!1:(a.hasMinicart=!0,a.display?e.add(a,“submit”,function(a){a.preventDefault(),b.show()}):e.add(a,“submit”,function©{c.preventDefault©,b.model.cart.add(g.parse(a))}),!0):!1},c.prototype.addItem=function(a){this.redraw(),this.show();var b=this.el.querySelectorAll("."+j.ITEM_CLASS);h.add(b[a],j.ITEM_CHANGED_CLASS)},c.prototype.changeItem=function(a){this.redraw(),this.show();var b=this.el.querySelectorAll("."+j.ITEM_CLASS);h.add(b[a],j.ITEM_CHANGED_CLASS)},c.prototype.removeItem=function(){this.redraw()},b.exports=c},{"./config":10,"./constants":11,"./util/css":14,"./util/events":16,"./util/forms":17,"./util/template":21,"./viewevents":23}],23:[function(a,b){“use strict”;var c,d=a("./constants"),e=a("./util/events");b.exports=c={click:function(a){var b=a.target,c=b.className;if(this.isShowing)if(c===d.CLOSER_CLASS)this.hide();else if(c===d.REMOVE_CLASS)this.model.cart.remove(b.getAttribute(d.DATA_IDX));else if(c===d.QUANTITY_CLASS)bb.setSelectionRange?“setSelectionRange”:“select”;else if(!/input|button|select|option/i.test(b.tagName)){for(;1===b.nodeType;){if(b===this.el)return;b=b.parentNode}this.hide()}},keyup:function(a){var b,c=this,e=a.target;e.className===d.QUANTITY_CLASS&&(b=setTimeout(function(){var a=parseInt(e.getAttribute(d.DATA_IDX),10),b=c.model.cart,f=b.items(a),g=parseInt(e.value,10);f&&(g>0?f.set(“quantity”,g):0===g&&b.remove(a))},d.KEYUP_TIMEOUT))},readystatechange:function(){if(/interactive|complete/.test(document.readyState)){var a,b,f,g;for(a=document.getElementsByTagName(“form”),f=0,g=a.length;g>f;f++)b=a[f],b.cmd&&d.COMMANDS[b.cmd.value]&&this.bind(b);this.redraw(),e.remove(document,“readystatechange”,c.readystatechange)}},pageshow:function(a){a.persisted&&(this.redraw(),this.hide())}}},{"./constants":11,"./util/events":16}]},{},[9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]);

Он будет отправлять форму на сервер, с которого нужно будет пересылать его на почту? И можно ли настроить отправку сразу на почту? Если да, то как?

Буду очень благодарна за помощь :)

Спешу предположить, что для того что бы отправить письмо непосредственно с фронтенда, можно воспользоваться API почтовых сервисов рассылок, к примеру https://www.mailgun.com

Тогда в итоге получится просто типа такого:

function sendMail() { $.ajax({ type: 'POST', url: 'https://mandrillapp.com/api/1.0/messages/send.json', data: { 'key': 'YOUR API KEY HERE', 'message': { 'from_email': 'YOUR@EMAIL.HERE', 'to': [ { 'email': 'RECIPIENT@EMAIL.HERE', 'name': 'RECIPIENT NAME (OPTIONAL)', 'type': 'to' } ], 'autotext': 'true', 'subject': 'YOUR SUBJECT HERE!', 'html': 'YOUR EMAIL CONTENT HERE! YOU CAN USE HTML!' } } }).done(function(response) { console.log(response); // if you're into that sorta thing }); }

Емейлы нельзя отправлять без серверного кода. Единственный вариант отправлять емейлы из браузера - использовать вызов API. Но тогда появляются другие проблемы (ключ API придется хранить на клиенте, и любые люди смогут использовать его для отправки писем). Скорее всего работа через API - это не то что тебе надо.

Минифицированный код никто не будет читать чтобы понять что он делает.

Будет ли отправлен емейл после отправки формы зависит только от серверного кода. Если ты работаешь с шаблонной админкой/фреймверком, то поищи в документации админки/фреймверка как отправляются емейлы.

Спасибо за помощь, плюс-минус разобралась :)