You must Sign In to post a response.
  • Category: HTML

    Code for sending a feedback from website to an email

    Friends,

    Can I get the code for sending a feedback from a website page to an email ,using html+php

    Regards,
    Anly
  • #759369
    Hi Anly,

    PHP has builtin function mail() which have below code structure.

    <?php
    $to = 'you@yoursite.com';
    $subject = 'Fededback from Website';
    $message = 'This is feedback regarding your website.';
    $headers = 'From: visitor@mysite.com' . "\r\n" .
    'Reply-To: visitor@mysite.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
    ?>

    But there have been always problem with SendMail or Mail function because to avoid spamming most of web hosts have disabled or set limit of mail.
    You can use any third party forms to put a HTML form in your page. One of trusted names is EmailMeForm.com which I have used. You can see the demo of working form at johnbhatt.com/contact.aspx

    All the Best.

    -------------
    Glad to be,
    John Bhatt
    Editor - DNS Forums
    https://www.pyarb.com

  • #759389
    Hello Anly Bertila,

    Refer the below code:

    HTML Markup:

    <!DOCTYPE html>
    <html>
    <head>
    <title>FeedBack Form With Email Functionality</title>
    <link href="css/elements.css" rel="stylesheet">
    </head>
    <!-- Body Starts Here -->
    <body>
    <div class="container">
    <!-- Feedback Form Starts Here -->
    <div id="feedback">
    <!-- Heading Of The Form -->
    <div class="head">
    <h3>FeedBack Form</h3>
    <p>This is feedback form. Send us your feedback !</p>
    </div>
    <!-- Feedback Form -->
    <form action="#" id="form" method="post" name="form">
    <input name="vname" placeholder="Your Name" type="text" value="">
    <input name="vemail" placeholder="Your Email" type="text" value="">
    <input name="sub" placeholder="Subject" type="text" value="">
    <label>Your Suggestion/Feedback</label>
    <textarea name="msg" placeholder="Type your text here..."></textarea>
    <input id="send" name="submit" type="submit" value="Send Feedback">
    </form>
    <h3><?php include "secure_email_code.php"?></h3>
    </div>
    <!-- Feedback Form Ends Here -->
    </div>
    </body>
    <!-- Body Ends Here -->
    </html>


    PHP Code:

    <?php
    if(isset($_POST["submit"])){
    // Checking For Blank Fields..
    if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
    echo "Fill All Fields..";
    }else{
    // Check if the "Sender's Email" input field is filled out
    $email=$_POST['vemail'];
    // Sanitize E-mail Address
    $email =filter_var($email, FILTER_SANITIZE_EMAIL);
    // Validate E-mail Address
    $email= filter_var($email, FILTER_VALIDATE_EMAIL);
    if (!$email){
    echo "Invalid Sender's Email";
    }
    else{
    $subject = $_POST['sub'];
    $message = $_POST['msg'];
    $headers = 'From:'. $email2 . "\r\n"; // Sender's Email
    $headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender
    // Message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // Send Mail By PHP Mail Function
    mail("recievers_mail_id@xyz.com", $subject, $message, $headers);
    echo "Your mail has been sent successfuly ! Thank you for your feedback";
    }
    }
    }
    ?>


    CSS Code:

    h3,p,label {
    text-align:center;
    font-family:'Raleway',sans-serif;
    color:#006400
    }
    h2 {
    font-family:'Raleway',sans-serif
    }
    input {
    width:100%;
    margin-bottom:20px;
    padding:5px;
    height:30px;
    box-shadow:1px 1px 12px gray;
    border-radius:3px;
    border:none
    }
    textarea {
    width:100%;
    height:80px;
    margin-top:10px;
    padding:5px;
    box-shadow:1px 1px 12px gray;
    border-radius:3px
    }
    #send {
    width:103%;
    height:45px;
    margin-top:40px;
    border-radius:3px;
    background-color:#cd853f;
    border:1px solid #fff;
    color:#fff;
    font-family:'Raleway',sans-serif;
    font-size:18px
    }
    div#feedback {
    text-align:center;
    height:520px;
    width:330px;
    padding:20px 25px 20px 15px;
    background-color:#f3f3f3;
    border-radius:3px;
    border:1px solid #cd853f;
    font-family:'Raleway',sans-serif;
    float:left
    }
    .container {
    width:960px;
    margin:40px auto
    }


    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763009
    [Response removed by Admin. Read forum policies.]

  • #763011
    Hello Jennifer,

    Read the question carefully than only provide the answer. The answer you have provided in C# back end coding. Where the person who asked code for html+php.

    Your answer doesn't meet his requirement.

    Hope you understand.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763014
    This is the feedback form html coding.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Feedback Form</title>
    </head>
    <body>
    <h1>Send Us Your Feedback!</h1>
    <form action="send_mail.php" method="post">
    <table>
    <tr>
    <td>Email Adress:</td>
    <td>
    <input type="text" name="email_address" value="" maxlength="100" />
    </td>
    </tr>
    <tr>
    <td>Comments:</td>
    <td>
    <textarea rows="10" cols="50" name="comments"></textarea>
    </td>
    </tr>
    <tr><td> </td>
    <td>
    <input type="submit" value="Submit" />
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    php coding for feedback processing.

    <?php
    // This function checks for email injection. Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
    function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
    return true;
    }
    else {
    return false;
    }
    }

    // Load form field data into variables.
    $email_address = $_REQUEST['email_address'] ;
    $comments = $_REQUEST['comments'] ;

    // If the user tries to access this script directly, redirect them to feedback form,
    if (!isset($_REQUEST['email_address'])) {
    header( "Location: feedback_form.html" );
    }

    // If the form fields are empty, redirect to the error page.
    elseif (empty($email_address) || empty($comments)) {
    header( "Location: error_message.html" );
    }

    // If email injection is detected, redirect to the error page.
    elseif ( isInjected($email_address) ) {
    header( "Location: error_message.html" );
    }

    // If we passed all previous tests, send the email!
    else {
    mail( "name@example.com", "Feedback Form Results",
    $comments, "From: $email_address" );
    header( "Location: thank_you.html" );
    }
    ?>

    I hope this will help and thanks for correcting me


  • Sign In to post your comments