Add of mailing script for contact form
This commit is contained in:
1 parent
a1c679b60a
commit
904f75c8de
7 files changed
+7637
-11
No files matched your search
+14
-11
@@ -1,9 +1,9 @@
|
||||
/* ===== Contact form settings =====
|
||||
1. Create a free key at https://web3forms.com with nelson.thomas.contact@pm.me
|
||||
2. Paste it below. Messages then arrive straight in your Proton inbox.
|
||||
Without a key (or if the service is unreachable), the form opens the
|
||||
visitor's mail app with the message already written. */
|
||||
var WEB3FORMS_KEY = "YOUR_ACCESS_KEY";
|
||||
The form posts to contact.php on your own server, which sends the message
|
||||
to your Proton inbox over SMTP (see LISEZMOI.txt).
|
||||
If the server can't be reached (e.g. site opened as a local file), the form
|
||||
opens the visitor's mail app with the message already written. */
|
||||
var CONTACT_ENDPOINT = "contact.php";
|
||||
var CONTACT_EMAIL = "nelson.thomas.contact@pm.me";
|
||||
|
||||
(function(){
|
||||
@@ -57,14 +57,17 @@ var CONTACT_EMAIL = "nelson.thomas.contact@pm.me";
|
||||
if(!form.checkValidity()){form.reportValidity();say('Fill in your name, a valid email, a subject and a message.','err');return}
|
||||
if(form.botcheck.checked)return;
|
||||
var d={name:form.name.value.trim(),email:form.email.value.trim(),company:form.company.value.trim(),subject:form.subject.value.trim(),message:form.message.value.trim()};
|
||||
if(!WEB3FORMS_KEY||WEB3FORMS_KEY==='YOUR_ACCESS_KEY'){mailtoFallback(d);return}
|
||||
btn.disabled=true;btn.textContent='Sending...';say('');
|
||||
fetch('https://api.web3forms.com/submit',{method:'POST',headers:{'Content-Type':'application/json',Accept:'application/json'},
|
||||
body:JSON.stringify({access_key:WEB3FORMS_KEY,from_name:'Portfolio: '+d.name,replyto:d.email,subject:'[Portfolio] '+d.subject,name:d.name,email:d.email,company:d.company,message:d.message})})
|
||||
.then(function(r){return r.json()})
|
||||
fetch(CONTACT_ENDPOINT,{method:'POST',headers:{'Content-Type':'application/json',Accept:'application/json'},
|
||||
body:JSON.stringify({name:d.name,email:d.email,company:d.company,subject:d.subject,message:d.message,botcheck:false})})
|
||||
.then(function(r){
|
||||
if(r.success){form.reset();say('Message sent. Thanks, I\'ll get back to you soon.','ok')}
|
||||
else throw new Error(r.message);
|
||||
return r.json().catch(function(){throw new Error('network')}).then(function(j){return {status:r.status,body:j}});
|
||||
})
|
||||
.then(function(r){
|
||||
if(r.body.success){form.reset();say(r.body.message,'ok');return}
|
||||
// Visitor-side problems (bad field, too many messages): show the server's message
|
||||
if(r.status===422||r.status===429||r.status===400){say(r.body.message,'err');return}
|
||||
throw new Error('server');
|
||||
})
|
||||
.catch(function(){mailtoFallback(d)})
|
||||
.finally(function(){btn.disabled=false;btn.textContent='Send message'});
|
||||
|
||||
Reference in new issue
Block a user