Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Get Simple Contact Form using HTML CSS and PHP
#1
Lightbulb 
Welcome to shediweb forum, in this topic I will showing you Simple Contact Form using HTML CSS and PHP very easy if you are a pro and hard for newbies ☑️

PHP Code:
<!DOCTYPE html>
<
html>

<
head>
    <link rel="stylesheet" 
          href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
    <link rel="stylesheet" 
          href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" 
          href=
"style.css" />
</
head>

<
body>
    <section id="last">
        <!-- heading -->
        <div class="full">
            <h3>Drop a Message</h3>

            <div class="lt">

                <!-- form starting  -->
                <form class="form-horizontal" method="post" 
                      action="contact.php">
                    <div class="form-group">
                        <div class="col-sm-12">
                            <!-- name  -->
                            <input type="text" class="form-control" 
                                   id="name" placeholder="NAME" 
                                   name="name" value="" />
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-12">
                            <!-- email  -->
                            <input type="email" class="form-control" 
                                   id="email" placeholder="EMAIL" 
                                   name="email"
                                value="" />
                        </div>
                    </div>

                    <!-- message  -->
                    <textarea class="form-control" rows="10" 
                              placeholder="MESSAGE" name="message">
            </textarea>

                    <button class="btn btn-primary send-button" 
                            id="submit" type="submit" value="SEND">
                        <class="fa fa-paper-plane"></i>
                        <span class="send-text">SEND</span>
                    </button>
                </form>
                <!-- end of form -->
            </div>

            <!-- Contact information -->
            <div class="rt">
                <ul class="contact-list">
                    <li class="list-item">
                        <class="fa fa-map-marker fa-1x">
                            <span class="contact-text place">
                                your address
                            
</span>
                        </i>
                    </li>

                    <li class="list-item">
                        <class="fa fa-envelope fa-1x">
                            <span class="contact-text gmail">
                                <a href="mailto:yourmail@gmail.com" 
                                   title="Send me an email">
                                    email@gmail.com</a>
                            </span>
                        </i>
                    </li>

                    <li class="list-item">
                        <class="fa fa-phone fa-1x">
                            <span class="contact-text phone">
                                (03312345678
                            
</span>
                        </i>
                    </li>
                </ul>
            </div>
        </div>
    </section>
</
body>
</
html

CSS
PHP Code:
    width100%; 
    heightauto
    justify-contentcenter
    background-color#ffb3b3; 
    
    .full
    width80%; 
    displayinline-block
    margin:2%; 
    margin-left10%; 
    text-aligncenter
    background-colorblack
    colorwhite
    border:15px solid orange
    border-radius5px
    margin-bottom8%; 
    margin-top8%; 
    
    .full h3
    font-size2rem
    display:block
    margin2%; 
    margin-bottom0
    
    .lt
    padding2%; 
    margin2%; 
    
    .rt
    padding2%; 
    margin2%; 
    
    .lt textarea
    width94%; 
    margin-left2.8%; 
    
    button
    margin2%; 
    
    .btn-primary
    background-colorblack
    border2px solid white
    border-radius5%; 
    
    .list-item
    margin-bottom2%; 
    list-style-typenone
    
    .list-item span
    margin-left10px
    font-size1.4rem
    
    .list-item a
    colorwhite
    displayinline-block
    
    .list-item a:hover
    text-decorationunderline
    
    .form-control
    background-colorblack
    
        
    
@media screen and (min-width770px){ 
    .full
        width70%; 
        margin-left15%; 
    
    .lt textarea
    width95%; 
    margin-left2.4%; 
    
    
        
    
@media screen and (min-width1100px){ 
    .full
        width65%; 
        margin-left17%; 
        margin-top5%; 
    
    .lt
        width55%; 
        displayinline-block
        floatleft
        margin-right0
    
    .rt
        width35%; 
        displayinline-block
        margin-left0
    
    .list-item
    margin-bottom10%; 
    
    .contact-list{ 
        margin-top22%; 
        padding-right8%; 
    
    .fa-envelope, .gmail
        displayinline-block
        widthauto
    
    

PHP code
: To add functionality to the form, we are using phpmailer. A separate php file “contact.php” is created and the name of the file is added in the HTML file in the form action field. 

<form class="form-horizontal" method="post" action="contact.php">

In the following code, we are getting the name, email, and message from the contact form. When “SEND” button is clicked, an email is sent from the website to the email address specified in the PHP code, with the subject line “This is the subject line”.

PHP Code:
<?php
// Get data from form  
$name $_POST['name'];
$email$_POST['email'];
$message$_POST['message'];

$to "yourEmail@gmail.com";
$subject "This is the subject line";

// The following text will be sent
// Name = user entered name
// Email = user entered email
// Message = user entered message 
$txt ="Name = "$name "\r\n  Email = " 
    $email "\r\n Message =" $message;

$headers "From: noreply@demosite.com" "\r\n" .
            "CC: somebodyelse@example.com";
if(
$email != NULL) {
    mail($to$subject$txt$headers);
}

// Redirect to
header("Location:last.html");
?>
  


Bookmarks

Forum Jump:


Users browsing this thread:
2 Guest(s)