I'm working on a project that's on a small scale for now. It's more about presentation and less about security.
All I need to do is have a form that will be filled out, then the user clicks submit and all the information collected from the form will be sent to a specified 'mailto:address'. I know that it would make a lot more sense to do this using php, but for now I only have html/css to work with.
Is there a way I can submit everything on the form to an email address? It can open up the user's email handler, but it doesn't have to.
I have 11 text fields and 2 sets of radios.
Well, what you are asking is totally possible, and I think the selected right answer is wrong. Take a look and read these two links:
Customize mailto
links http://blog.escapecreative.com/customizing-mailto-links/
The default action of mailto depends on the browser so, if you try it and my solution could not work in your browser the cause may be for this reason: Configuring mailto
Mailto links do nothing in Chrome but work in Firefox?
Here is the jsfiddle: http://jsfiddle.net/g3qazhf8/ and I'm using jquery to make my life easier:
javascript
function sendEmail(){
var answerArr = [];
$("input, textarea").each(function(){
if($(this).attr("type") === "radio"){
if($(this).is(":checked")){
answerArr.push($(this).val());
}
}else{
answerArr.push($(this).val());
}
});
var body = answerArr.join("\n");
var mailto = "[email protected]";
var a = document.createElement('a');
a.href = "mailto:" + mailto + "?body=" + escape(body);
console.log(a.href);
a.click();
}
$(document).on("click",".submit",sendEmail);
HTML
<textarea> your message </textarea>
<input type="text" placeholder="name" name="name" />
<input type="text" placeholder="lastname" name="lastname" />
<label>
<input type="radio" name="rboption" value="yes" /> YES
</label>
<label>
<input type="radio" name="rboption" value="no" />NO
</label>
<br>
<a href="#" target="_blank" style="display:inline-block; background:#333; color:#FFF; padding:5px 10px 5px 10px; margin:15px 0 0 0; text-decoration:none" class="submit">Sent the email</a>
Btw, you should try the solution on your localhost. I will attach an image proving that it's working:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments