How to create an email form that can send email using html

Html

Html Problem Overview


I know there are a lot of examples using the mailto: post action to send emails using just html forms.

But using this will actually popup the send email dialog box e.g. outlook dialog box. And it actually uses our own smtp server to send the email.

Is there any way to create html forms that will simply send email upon submission?

Is there a javascript api which can achieve this effect? Say for example node.js?

Can anyone provide some code samples?

Html Solutions


Solution 1 - Html

As the others said, you can't. You can find good examples of HTML-php forms on the web, here's a very useful link that combines HTML with javascript for validation and php for sending the email.

Please check the full article (includes zip example) in the source: http://www.html-form-guide.com/contact-form/php-email-contact-form.html

HTML:

    <form method="post" name="contact_form"
    action="contact-form-handler.php">
        Your Name:
        <input type="text" name="name">
        Email Address:
        <input type="text" name="email">
        Message:
        <textarea name="message"></textarea>
        <input type="submit" value="Submit">
    </form>

JS:

    <script language="JavaScript">
    var frmvalidator  = new Validator("contactform");
    frmvalidator.addValidation("name","req","Please provide your name");
    frmvalidator.addValidation("email","req","Please provide your email");
    frmvalidator.addValidation("email","email",
      "Please enter a valid email address");
    </script>

PHP:

    <?php
    $errors = '';
    $myemail = '[email protected]';//<-----Put Your email address here.
    if(empty($_POST['name'])  ||
       empty($_POST['email']) ||
       empty($_POST['message']))
    {
        $errors .= "\n Error: all fields are required";
    }
    $name = $_POST['name'];
    $email_address = $_POST['email'];
    $message = $_POST['message'];
    if (!preg_match(
    "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
    $email_address))
    {
        $errors .= "\n Error: Invalid email address";
    }
    
    if( empty($errors))
    {
    $to = $myemail;
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n ".
    "Email: $email_address\n Message \n $message";
    $headers = "From: $myemail\n";
    $headers .= "Reply-To: $email_address";
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-form-thank-you.html');
    }
    ?>

Solution 2 - Html

you can use Simple Contact Form in HTML with PHP mailer. It's easy to implement in you website.

Otherwise you can watch the demo video in following link: Youtube: Simple Contact/Feedback Form in HTML-PHP mailer

When you are running in localhost, you may get following error:

Warning: mail(): Failed to connect to mailserver at "smtp.gmail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in S:\wamp\www\sample\mailTo.php on line 10

And this is the screenshot of HTML form: Simple Form

And this is the main PHP coding:

<?php
if($_POST["submit"]) {
    $recipient="[email protected]"; //Enter your mail address
    $subject="Contact from Website"; //Subject 
    $sender=$_POST["name"];
    $senderEmail=$_POST["email"];
    $message=$_POST["comments"];
    $mailBody="Name: $sender\nEmail Address: $senderEmail\n\nMessage: $message";
    mail($recipient, $subject, $mailBody);
	sleep(1);
	header("Location:http://blog.antonyraphel.in/sample/"); // Set here redirect page or destination page
}
?>

Solution 3 - Html

As many answers in this thread already suggest it is not possible to send a mail from a static HTML page without using PHP or JS. I just wanted to add that there a some great solutions which will take your HTTP Post request generated by your form and create a mail from it. Those solutions are especially useful in case you do not want to add JS or PHP to your website.

Those servers basically can be configured with a mail-server which is responsible for then sending the email. The receiver, subject, body etc. is received by the server from your HTTP(S) post and then stuffed into the mail you want to send. So technically speaking it is still not possible to send mails from your HTML form but the outcome is the same.

Some of these solutions can be bought as SaaS solution or you can host them by yourself. I'll just name a few but I'm sure there are plenty in case anyone is interested in the technology or the service itself.

Solution 4 - Html

Short answer, you can't.

HTML is used for the page's structure and can't send e-mails, you will need a server side language (such as PHP) to send e-mails, you can also use a third party service and let them handle the e-mail sending for you.

Solution 5 - Html

You can't, the only things you can do with html is open your default email application. You must use a server code to send an email, php, asp .net....

Solution 6 - Html

You can't send email using javascript or html. You need server side scripts in php or other technologies to send email.

Solution 7 - Html

Html by itself will not send email. You will need something that connects to a SMTP server to send an email. Hence Outlook pops up with mailto: else your form goes to the server which has a script that sends email.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondfdfdView Question on Stackoverflow
Solution 1 - HtmlYiselaView Answer on Stackoverflow
Solution 2 - HtmlAntony RaphelView Answer on Stackoverflow
Solution 3 - HtmlLOLWTFasdasd asdadView Answer on Stackoverflow
Solution 4 - HtmlSpoodyView Answer on Stackoverflow
Solution 5 - HtmlChristophe DeboveView Answer on Stackoverflow
Solution 6 - HtmlrobertView Answer on Stackoverflow
Solution 7 - HtmlSid MalaniView Answer on Stackoverflow