user3117575
user3117575

Reputation:

HTML form: Letting a user Email you with a already made email

So, I want to make a help form that allows users to email me with my already made email instead of using theirs. So what I mean is a form that they can just Enter text, and click the submit button and it sends to me without the user having to do anything more.

What I've tried so far is:

<form action="MAILTO:[email protected]" method="post" enctype="text/plain">
    Username:<br>
    <input type="text" name="name"><br>
    Help comment:<br>
    <input type="text" name="mail" value="50"><br>
    <input type="submit" value="Send">
</form>

But on Safari (not sure about the other browsers) This opens a new window prompting for the user to fill out an email. How could I do this where it would just send it to my email without them having to write an email themselves, but instead just simply clicking send and having my email ([email protected]) preset for the user, so no window will pop up or anything.

Upvotes: 0

Views: 470

Answers (4)

Hassam Salam
Hassam Salam

Reputation: 266

This will allow you to get the values from HTML input text boxes and then pass these values to send Email.Hope it will help..

function BuildEmailBody() 
{
var  retBody;

retBody = document.getElementById("txtMessage").value;

return retBody;                                         
}

 function ProcessSubmition() {

    var stringEmailBody = BuildEmailBody();                 //the value of 'txtmessage' will asign to stringEmailbody

    var stringTo = document.getElementById("txtEmail").value;   //Email from textbox of id 'txtEmail'

     var stringSubject = document.getElementById("txtSubject").value;  //subject from textbox of id 'txtSubject'

    window.location.href = "mailto:" + stringTo + "?subject=" + stringSubject + "&body=" + stringEmailBody;

}

Upvotes: 0

charlie
charlie

Reputation: 44

To do that you need to have your site uploaded on a host that supports php. It can't be done with only client side scripting.

Html code:

<form id="form" method="post" action="sendMail.php">
         <fieldset>
             <label>name</label>
             <input type="text" name="name"/>
             <label>surname</label>
             <input type="text" name="surname"/>
             <label>e-mail</label>
             <input type="text" name="mail"/>
         </fieldset>
         <fieldset>
             <label>message</label>
             <textarea name="msg" cols="85" rows="8"></textarea>
         </fieldset>
         <fieldset>
             <input type="submit" value="send"/>
         </fieldset>
</form>

PHP code:

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);

$contact = array('name' => $_POST['name'],
    'surname' => $_POST['surname'],
    'mail' => $_POST['mail'],
    'msg' => $_POST['msg']
);

if ($contact['name'] != "" && $contact['surname'] != "" && $contact['mail'] != "" && $contact['msg'] != "") {

    $name = $contact['name'];
    $surname = $contact['surname'];
    $mail = $contact['mail'];
    $msg = $contact['msg'];

    // message can be built as you want, you can use html and inline css in it.
    $message = "name: ".$name."<br/>"."surname: ".$surname."<br/>".$msg;

    $to = "[email protected]";
    $subject = "subject";

    $headers = "From: " . $mail . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    mail($to, $subject, $message, $headers);
}
?>

Upvotes: 1

BuddhistBeast
BuddhistBeast

Reputation: 2670

To make it easier on you, I have provided an example of the PHP mail function. However, you are going to want to consider adding a few things such as... an input for the subject, which is always handy. Also, make your input area become a text area, I find it easier to write something that I am fully able to see vs. only being able to see a limited view of what I am currently writing.

    $messageBody = $_POST['mail'];
    $to = '[email protected]';
    mail($to, $_POST['subject'], $messageBody);

I think these are primarily the things you really need to focus on. Take into account you are able to house a fourth parameter, generally a CC, BCC, or a FROM section (in the manual, they refer to it as the 'headers' section), which could also be helpful for you unless you plan to have somebody write their name at the end of the message (probably not very good etiquette).

Now your form.. Well.. You can structure it annnyyywwaaayyy you want.. in fact.. there are multiple ways to skin a cat.. and to create a form.. Here is quick demo of a possibility of making your form a little bit better. And if you want a little bit more reasoning as to why I used an unordered list vs a table, here is a SO Question that can give you some pros and cons over what is better and so forth. My JsFiddle can also give you an idea of how to make the display of your form look... clean.

Also, look into how you want to validate your form... Do you want to do it via PHP, where it will require the user to hit the submit button before it will look through for any errors (maybe to check for a username or for an actual message, thus avoiding spam or unwanted emails) or maybe you want to try to incorporate some browser side scripting with JavaScript to automatically check for these things without even touching that submit button.

Regarding the database, I would advise validating and making sure that you are preventing SQL injections (I will not be the only person to bring this up), which will help protect your database if you plan to upload this message and keep it for a while.

There is much thought that must be placed into creating a form, whether it is the simple HTML code, all the way through MySQL or any database code you may be working with.

Last, please please please look at the manual. In fact, I learn more from the manual now then I do from looking at other people's code because it gives real, working examples to choose from. So visit this site to make your life a little bit easier.

Upvotes: 0

LynxZh
LynxZh

Reputation: 835

You may need some backend support. Simple javascript + html can't do that because it didn't get connect to a smtp server and send email from that. As you select php I suppose that's your backend. So you can use the PHP mail component and submit your form into one backend php page and translate the data from the form into the mail function. You can get more from the php doc -> http://www.php.net/manual/en/function.mail.php

Upvotes: 0

Related Questions