Hello.I have this contact form <form method="post" action="mailto:"> <label for="nm">Name: </label> <input type="text" id="nm"> <label for="em">Email: </label> <input type="text" id="em"> <label for="comm">Your comments: </label> <textarea id="comm"></textarea> <br> <input type="submit" value="Send email"> </form> When i press submit button message is not sent straight but default email client opens a new window.I don't want that.I want that user could sent message just by pressing submit. So,i heard it is impossible to do just with html? So,i'm studying online course web design.I sent this contact form to my tutor and she said that it is bad and i need to do so that message could be sent without writing it again in email client.And she says that it is possible to do with html. Can someone explain me how???? I was looking for information on the internet but everyone say that i can't do it just with html. I'm telling that already few days to my tutor,but she still says that i can. So,who is wrong? Help me please.
Hi, Igozorus It is true that giving up HTML (and using PHP or ASP for sending the e-mail) would have its advantages, such as hiding your e-mail address. As far as I know, having the "action" value be "mailto:something" will necessarily cause the user's e-mail client to open. Your code makes the user's e-mail client (Outlook, Thunderbird, etc) open, but the problem is that the user has to type the message again. However, there's a little trick that you can use so the e-mail client will open with message already populated, and it can be done in 3 steps: 1- change the form's method from "post" to "get" 2- change the message textarea's ID from "comm" to "body" 3- add a "name" attibute to the message textarea, whose value should also be "body". It'd end up like this: <form method="get" action="mailto:"> <label for="nm">Name: </label> <input type="text" id="nm"> <label for="em">Email: </label> <input type="text" id="em"> <label for="body">Your comments: </label> <textarea id="body" name="body"></textarea> <br> <input type="submit" value="Send email"> </form> Please try this out and let me know if it worked (please note that you can also make it so the subject field of the client's email starts already populated as well). Ken
in your first coding line you put action before email. It means if someone click the submit button it will automatically open an outlook. In my knowledge after action you have to put php cgi script.
May this help you: <?php $action=$_REQUEST['action']; if ($action=="") /* display the contact form */ { ?> <form action="" method="POST" enctype="multipart/form-data"> <input type="hidden" name="action" value="submit"> Your name:<br> <input name="name" type="text" value="" size="30"/><br> Your email:<br> <input name="email" type="text" value="" size="30"/><br> Your message:<br> <textarea name="message" rows="7" cols="30"></textarea><br> <input type="submit" value="Send email"/> </form> <?php } else /* send the submitted data */ { $name=$_REQUEST['name']; $email=$_REQUEST['email']; $message=$_REQUEST['message']; if (($name=="")||($email=="")||($message=="")) { echo "All fields are required, please fill <a href=\"\">the form</a> again."; } else{ $from="From: $name<$email>\r\nReturn-path: $email"; $subject="Message sent using your contact form"; mail("", $subject, $message, $from); echo "Email sent!"; } } ?>
Gah, creativewebmaster! Please wrap your code properly, no one can read it when it looks like that! <?php $action = $_REQUEST['action']; if ( $action == "" ) /* display the contact form */ { ?> <form action="" method="POST" enctype="multipart/form-data"> <input type="hidden" name="action" value="submit"> Your name:<br /> <input name="name" type="text" value="" size="30"/><br /> Your email:<br /> <input name="email" type="text" value="" size="30"/><br /> Your message:<br /> <textarea name="message" rows="7" cols="30"></textarea><br /> <input type="submit" value="Send email"> </form> <?php } else /* send the submitted data */ { $name = $_REQUEST['name']; $email = $_REQUEST['email']; $message = $_REQUEST['message']; if ( ( $name == "" ) || ( $email == "" ) || ( $message == "" ) ) { echo "All fields are required, please fill <a href=\"\">the form</a> again."; } else { $from = "From: $name <$email>\r\n Return-path: $email"; $subject = "Message sent using your contact form"; mail( "youremail@yoursite.com", $subject, $message, $from ); echo "Email sent!"; } } ?> PHP: However, this is reliant upon PHP being installed on the machine. In order for the page to send an email, you will need to use a server-side scripting language such as PHP. The only other alternative is to use mailto: in a link or form (as Ken has demonstrated) to pass the necessary query vars to your browser which, in turn, will open the users default email client and attempt to send it the variables to populate the fields as necessary.
Alright.Thank you all who tried to help. Ken.Developer,no,it doesn't work.It's the same-opens an email client and message field is empty. For the others-i told you-my tutor says that it is possible to do just with HTML and i can't use PHP. So,maybe at least there is a way to write a code with html that when user writes a message on a website and press submit-and email client opens,but his message are already in the field? Is it possible?
To do this with just HTML (as your instructor requested) you need to add the subject to the URL: <a href="mailto:youremail@mail.com?subject=Your%20Subject&body=Message%20From">Email Us</a> HTML: Notice that this will all be sent as a GET request (appended to the URL). When your email client opens, it reads the name/value pairs from the URL. To start the name/value pairs, we use ? and the & symbol to add more pairs. I use %20 to add a space between words.
This is the confirm solution to your Problem. Be cool. <?php if (isset($_POST['contact_email'])) { $contact_email = $_POST['contact_email']; if (!empty($contact_email)){ $to = 'abcd@gmail.com'; $subject = 'Submitted.'; $headers = 'From :' .$contact_email; if (@mail($to,$body, $headers)) { echo 'Thanks for submitting....We will contact you soon'; } else{ echo 'error';} } else{ echo 'All fields compulsory';} } ?> <form action="index.php" method="POST" > Email : <input type="text" name="contact_email" style="color:red;margin-bottom:5px;"> <input type="submit" value="SUBSCRIBE" > </form> PHP:
I don't know if your goal is to just get a working contact form or if it's to figure out how to code one. If it's to get a working contact form and you're not worried about how to code it, you can try this contact form generator or you can google something like "free php contact form generator".
Thanks everyone for help.Can't say which answer is the best yet,but my tutor said that i need to do it WITHOUT PHP.Waiting for her response
So this is what my tutor said: "It should work in a way which does not require the message to be entered twice - this would be frustrating for the site users." So the only way to do that with html is like ekim941 said- <a href="mailto:?subject=Your%20Subject&body=Message%20From">Email Us</a> ? Is it not possible to do the form and write message only once?Because with the code above there won't be a form,only link
If a person hits their browser back button, there is no reason why the form should reset. All the information should still be there, unless there is something currently in your code that deletes all the form info every time you hit the back button.
With a little javascript, you could grab the data from the form fields and build the URL for the mailto link. Then, make the link active once the data has been entered. But, does using Javascript count as only using HTML?