#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Mailto form that opens a new email


    Hi,

    I need help with creating a form that I can use on my internal site. I just need something simple. It needs to have two fields that the user can fill in: Subject and Comments (and a submit button). When the user submits, it would launch a new email which has the To: field pre-filled with my value (call it support@help.com for now) and the subject and comments get pre-filled using the form data. Then all the user needs to do is hit Send. Since this is used internally, I can say for sure that the users all have Outlook.

    I found some examples online, but they all seem to put
    "subject=(subject from form)
    body=(comments text form the form)" like that in the body. I just need the comments form data, but it includes field names too.

    Here's what I have so far:
    Code:
    <form action="mailto:support@help.com" method="post">
    	Subject: 
    	<input name="subject" value=""><br><br>
    	Comments:<br>
    	<textarea name="body"></textarea>
    	<br>
    	<input type="submit" value="Submit"> 
    </form>
    I don't really need validation since the email is pre-filled, but it would be nice to be able to check if both fields are empty (if one is filled in that's fine then.) That's way above what I can do though.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    One for a bit of javascript I think:
    Code:
    <script type="text/javascript">
    function sendMail(subject, body) {
        if (document.getElementById('body').value == "") {
            alert("Please enter a comment");
        } else {
            window.location = "mailto:support@help.com?subject=" + subject + "&body=" + body;
        }
    }
    </script>
    
    <form>
        <label for="subject">Subject:</label>
        <input id="subject" />
        <label for="body">Comments:</label>
        <textarea id="body"></textarea>
        <input type="button" value="Submit" onClick="sendMail(document.getElementById('subject').value, document.getElementById('body').value)" />
    </form>
    Checks if the comment field is empty and displays a message if so, otherwise opens the users email client with subject and body fields pre-filled.
    Last edited by Edge360; July 15th, 2013 at 07:07 AM.

IMN logo majestic logo threadwatch logo seochat tools logo