How To Make A Form For Sending Emails

Table of contents:

How To Make A Form For Sending Emails
How To Make A Form For Sending Emails

Video: How To Make A Form For Sending Emails

Video: How To Make A Form For Sending Emails
Video: HTML Form to Mail | Create Full Functional HTML Form Without Any Back-end 2024, November
Anonim

When creating a website, webmasters often give users the opportunity to send written messages to the service administrator. A special form is used for this. You can write the simplest version of this form yourself.

How to make a form for sending emails
How to make a form for sending emails

Instructions

Step 1

As a rule, the form for sending a letter on the site consists of two main fields: the message header field and the field for entering the message text. The sender does not need to specify the email address of the site administrator, since it is written in the code itself. This option is convenient because the administrator can receive letters without showing his email address.

Step 2

The form itself, into which the text will be entered, is written in simple html. The code could be something like this:

Subject

Message:

Step 3

The above code will create a form with two fields - Subject and Message. There will also be two buttons on it - "Send" and "Clear". You can place this code in a convenient place on the site page. The form will be present, but not yet functional. In order for button clicks to lead to the desired result, you need to add the following PHP script to the site:

<?

$ to = "email @ address";

mail ($ to, "$ sub", $ mes);

?>

Step 4

Replace the line "email @ address" with the desired e-mail. Copy the script into a regular "Boknot", save it as send.php (first save it as send.txt, then rename the extension to *.php) and put it in the same folder as the site page. This is the simplest version of the form for sending letters, you can change and refine it in the way you want. For example, by adding an echo statement to the script, you can display this or that message on the screen after sending a letter. You can also change the size of the form, its color, button names, etc. at your discretion.

Recommended: