-3

I have an HTML form; can I send an email with the contents of the form when the user clicks the submit button, using only HTML?

How do I have the email sent with a certain subject?

Dexter
  • 18,213
  • 4
  • 44
  • 54
  • Are you using only html or any other languages? – user3272686 Feb 28 '14 at 23:51
  • Set the action attribute to the URL of a server side program. Then write a program, in the language of your choice, that processes the form data and sends the email. Configure your server to run it when that URL is hit. – Quentin Feb 28 '14 at 23:51

4 Answers4

1

HTML is run on the client side. You need a server if you want to send an email. Something like node or php. Once you have a server running and hosting your html, you can lookup the documentation to send an email.

Here's an example of a php server sending an email: How to send an email using PHP?

Community
  • 1
  • 1
Brian Anderson
  • 621
  • 7
  • 22
1

you need php or server side language to make this work.......e.g.

HTML FILE:

    <form action="answer.php" method="POST">
    email address: <input type="text" "name="email"/>
    Name: <input type="text" name="name"/>
    <input type="submit"/>
    </form>

Php file answer.php

    <?php
    //form validation
    if( $_POST ) {
       $name=$_POST['name'];
       $email=$_POST['email'];
       $subj= "my subject or do a form field!";
       $content = "content from a form field etc!";
       $to= "myemail@email.com";
       $from = "from: $email";
    }

    if ( $email ) {
       mail($to, $subj, $content, $from);
    }

    ?>

To be honest you are opening up a whole new chapter on your skills. the above code will be much abused by spammers, etc. You might be better to look at wordpress which you can use to provide a lot of the php code you need through plugins etc. You can use a outlook open but again this opens your email to spammers, etc.

David
  • 5,897
  • 3
  • 24
  • 43
0

if you are using php you can use phpmailer phpmailer

Very easy to use and it has great documentation

You can also use "MAILTO:someone@example.com" as your form action.

<form action="MAILTO:someone@example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
mathius1
  • 1,381
  • 11
  • 17
-1

Without using PHP, your only option is to set up your fields and let the user complete the email from their Email client (ie. Outlook). See this link for the code: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_mail.

KayleighMJ
  • 11
  • 2