How can I make, when clicking a button, send an email with the data included from the form?

前端 未结 2 2053
误落风尘
误落风尘 2020-12-22 06:39

So I simply need to collect the information from a HTML form I made and send it via an email. How can I achieve this? Do I need PHP or some stuff like that? What should I pu

相关标签:
2条回答
  • You have some studying ahead of you. Fortunately, there are free materials that will help you.

    I recommend submitting the form using AJAX -- it's not that difficult. At all. What AJAX does is allow you to submit the form without navigating the user to a new page. User stays on page as form is submitted. Here's a free 10-min video that explains it:

    https://phpacademy.org/videos/submitting-a-form-with-ajax

    Also, there are about 200 ten-minute videos on the next link, and you should do them all. But the ones for sending a form are lessons 98 - 103:

    https://www.thenewboston.com/videos.php?cat=11

    Summary of FORMS: Forms are comprised of a number of HTML fields (usually <input> elements) that are enclosed by <form></form> tags. When the submit button is pressed, the form data is "POSTED" to the (usually PHP) file specified in the <form action="somefile.php" attribute of the form tag. Basically, the form elements are collected in a series of varName=varValue pairs and sent to another (often PHP) file for processing.

    Every HTML element can have a name= attribute:

    <input type="text" name="fname" />
    

    When the form is submitted, the receiving (PHP) file receives the form data as: variable name ==> "name=" attribute and variable contents ==> field contents

    And that, in a nutshell, is how FORMs work.

    How do you know what kind of "receiving" file your form will use? If your web page is hosted on a typical "CPanel" hosting account, you can use PHP. If a Microsoft server, you will use an M$ solution (aspx?)


    Here are some very simple examples that will help you get the gist of AJAX:

    A simple example

    More complicated example

    Populate dropdown 2 based on selection in dropdown 1

    0 讨论(0)
  • 2020-12-22 07:30

    PHP is certainly not the only way to send e-mail from a web form, but it is a very common method (especially for people creating their first form).

    Here is one reference that may help you to get started, and explain why other methods (i.e. HTML-only, JavaScript) don't work for your needs:

    http://www.html-form-guide.com/email-form/html-email-form.html

    0 讨论(0)
提交回复
热议问题