0

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:xeroelixirmain@gmail.com" 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 (xeroelixiry@gmail.com) preset for the user, so no window will pop up or anything.

  • I think that this depends on a lot of things... I know there is a way to do this in PHP without automatically prompting the user to fill out an email. What server are you running this through? – BuddhistBeast Dec 31 '13 at 07:50
  • 3
    you would need this to happen server side in response to your form... javascript (or the browser) can't send mail – Offbeatmammal Dec 31 '13 at 07:51
  • @Offbeatmammal but I need an email –  Dec 31 '13 at 07:52
  • No you don't. Server side lets you do this without getting the other persons email and it will send it to you if that is your request.It might be that time to start dabbling in PHP, Javascript will only handle browser side services. HTML and CSS... well.. it's not even coding and to top it off, it is also pretty much browser side too. – BuddhistBeast Dec 31 '13 at 07:52
  • @BuddhistBeast what I mean is I would prefer it to email me. If not, I would reather have it stored in a database, so if you can help, I would be greatful. –  Dec 31 '13 at 07:54
  • Offbeatmammal is correct. You need to set up your server to send the email. – jameslafferty Dec 31 '13 at 07:54
  • You need to write server side script to achieve this :) – Amit Dec 31 '13 at 07:55
  • @user3117575, I understand that. Server side works by sending the email addressed to the "to" section of the PHP call or any call for that matter. Have you used PHP before? – BuddhistBeast Dec 31 '13 at 07:55
  • see something like http://stackoverflow.com/questions/9829284/php-for-email-contact-form?rq=1 for a PHP sample ... the recipient would be you – Offbeatmammal Dec 31 '13 at 07:55
  • @BuddhistBeast Yes, I have. –  Dec 31 '13 at 07:56
  • @user3117575 then you shouldn't have too hard of a problem using the mail function. But you storing it into a database is a completely different story. – BuddhistBeast Dec 31 '13 at 07:57
  • @BuddhistBeast alright, thanks, I'll check it out, and if it fits my needs I'll be sure to vote best on your answer if you post one. –  Dec 31 '13 at 07:58

4 Answers4

1

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 = "your_mail@gmail.com";
    $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);
}
?>
charlie
  • 46
  • 2
0

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

LynxZh
  • 825
  • 5
  • 9
0

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 = 'youremail@whateverworks.com';
    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.

Community
  • 1
  • 1
BuddhistBeast
  • 2,652
  • 2
  • 21
  • 29
0

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;

}
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Hassam Salam
  • 246
  • 3
  • 13