- This topic is empty.
-
AuthorPosts
-
March 18, 2016 at 4:28 pm #239501
Timothy Smith
ParticipantI am creating a simple form for on a non profit web page. I want the user/donor to be able to simply click send and have the site/form send an email to the non-profit. I do not want an email client open up on the users screen. I just want it to send an email behind the scenes.
I was hoping to do this on a simple static web site (html/css/js). Every example I come across wants me to use some sort of php or other backend server.
This is want I am currently using
<form method="GET" action="mailto:[email protected]" enctype="text/plain"> <div>Subject</div> <input type="text" name="subject" /> <div>Name</div> <input name="Name" /> <div>E-Mail</div> <input name="E-Mail Address" /> <div>Message</div> <textarea name="Message"></textarea> <br/> <input type="submit" value="Send" /> <input type="hidden" name="body" /> </form>
…
var form = document.getElementsByTagName('form')[0]; form.addEventListener('submit',contact,false); function contact(e) { // Prevent Default Form Submission e.preventDefault(); var target = e.target || e.srcElement; var i = 0; var message = ''; // Loop Through All Input Fields for(i = 0; i < target.length; ++i) { // Check to make sure it's a value. Don't need to include Buttons if(target[i].type != 'text' && target[i].type != 'textarea') { // Skip to next input since this one doesn't match our rules continue; } // Add Input Name and value followed by a line break message += target[i].name + ': ' + target[i].value + "\r\n"; } // Modify the hidden body input field that is required for the mailto: scheme target.elements["body"].value = message; // Submit the form since we previously stopped it. May cause recursive loop in some browsers? Should research this. this.submit(); }
This works but opens an email client on the users side and obviously does not hide the mailto email address.
Is there a better solution for this with say wordpress or ruby on rails without the need to use mandrill, email chimp, constant contact, etc?
Is there a FREE custom solution to this… using a gmail account perhapses?
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.