In this chapter, we'll learn how to create the basic contact form and how to set it to send mail to your address. We have two types of contact forms in our template: short and classic.

Classic Contact Form

This classic contact form lets visitors send you a message with contact details to establish a connection. Here is a general form markup:

...
Contact Form
form
    div
        Field: Name
        labelYour name/label
        input
        Field: Email
        labelYour email:/label
        input
        Field: Message
        labelYour message:/label
        textarea/textarea
        Form Button
        buttonSend Message/button
        div/div
    /div
    span/span
/form
...

To make everything work, you should edit the mail.php file and specify your email address in the $mail_to variable.

<?php
/**
* Author: Shadow Themes
* Author URL: http://shadow-themes.com
*/

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    # Replace this email with your email address
    $mail_to = "yourmail@example.com";
    
    ...
}
?>

Short Contact Form

The short contact form lets visitors share their email addresses without any additional messaging to let you contact them or use it for a news subscription list. Here, we will look at the basic markup for a better understanding of the form code, but in actual usage in our template, the inner markup may differ depending on a block, like Call to Action or Hero Section.

...
Short Contact Form
form
    div
        Mail Field
        input
        Form Button
        button
            span/span
        /button
        div/div
    /div
    span/span
/form
...

The same as in the previous example, you should edit the PHP file called mail-short.php and specify your email address in the $mail_to variable. Also, below the $mail_to, you can write some text for the $message variable to display to you in the received message.

<?php
/**
* Author: Shadow Themes
* Author URL: http://shadow-themes.com
*/

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    # Replace this email with your email address
    $mail_to = "yourmail@example.com";

    # Message: You can modify that string with your text.
    $message = "";

    ...
}
?>

Please note that this is a straightforward basic contact form. There is no captcha or any serious spam protection. To secure your contact form, you should find third-party solutions. For example, here you can find the information about the reCaptcha by Google https://www.google.com/recaptcha/