#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Lilburn
    Posts
    4
    Rep Power
    0

    Question How can i add Email Text Box on my website home page?


    how can i add Email Text Box on my website home page?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    23
    Rep Power
    0
    Here is a php example of an email form:

    php code:

    <?php
    $sendMessage = false;

    if (isset($_REQUEST['message']) && isset($_REQUEST['email']) && isset($_REQUEST['subject']))
    {
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $message = $_REQUEST['message'];
    if (strlen($_REQUEST['message']) > 0 && strlen($_REQUEST['email']) > 0 && strlen($_REQUEST['subject']) > 0)
    {
    $sendMessage = true;
    }
    }

    if ($sendMessage)
    {
    //something@example.com need to be changed to your email-adress
    mail("something@example.com", $subject, $message, "From:" . $email);
    echo "Thank you for using our mail form";
    }
    else
    {?>
    <form method="post" action="">
    <span>From Email:</span><input name="email" type="text" /><br />
    <span>Mess. Subject:</span><input name="subject" type="text" /><br />
    Message:<br />
    <textarea name="message" rows="15" cols="40"></textarea><br />
    <input type="submit" value="Send Message" />
    </form>
    <?php
    }
    ?>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0
    Hi,

    I wish to know why not some validation form or filters can be added? Try this with the above suggested PHP code.

    / Begin Form Validation

    // Filter Input
    function spamcheck($field)
    {
    //filter_var() sanitizes the e-mail
    //address using FILTER_SANITIZE_EMAIL
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);

    //filter_var() validates the e-mail
    //address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
    else
    {
    return FALSE;
    }
    }

    //Error Handler Function
    function customError($errno, $errstr)
    {
    echo "<b>Error:</b> [$errno] $errstr<br />";
    die();
    }

    //set error handler
    set_error_handler("customError",E_USER_WARNING);

    // Checks if Information Exists
    if (!isset($_POST['name']))
    trigger_error("No name entered",E_USER_WARNING);

    if (!isset($_POST['email']))
    trigger_error("No email entered",E_USER_WARNING);

    if (!isset($_POST['comment']))
    trigger_error("No comment entered",E_USER_WARNING);


    // Check If The Email Address Is Invalid
    $mailcheck = spamcheck($_POST['email']);
    if ($mailcheck==FALSE)
    trigger_error("The email you entered is not valid".E_USER_WARNING);


    // Get User's IP Address. This Is Optional
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else {
    $ip = $_SERVER['REMOTE_ADDR'];
    }


    $message = "Name: ".$_POST['name']."\n\n" .
    "Email: ".$_POST['email']."\n\n" .
    "Message:\n" .
    $_POST['comment']."\n\n" .
    "---------------------------------\n" .
    "Sender IP: ".$ip
    ;


    $message = wordwrap($message, 70);


    // Create Email Headers
    $emailfrom = $_POST['email'];
    $subject = "Message from ".$_POST['name'];
    if (!mail("------THE EMAIL TO SEND TO GOES HERE------", "$subject", $message, "From: $emailfrom" ))
    echo ("<p>Our server encountered a problem with your submission<br/> \n"
    );
    else
    echo ("<div style=\"text-align:center;\"><p>Thank you!<br/> \n"
    );


    <form action="------THE URL OF THE PAGE YOU'RE USING THIS ON GOES HERE------" method="post">
    <fieldset>
    <label>Name</label><br /><input name="name" type="text" id="name" size="32" /><br/><br />
    <label>Email</label><br /><input name="email" type="text" id="email" size="32" /><br/><br />
    <label>Message</label><br /><textarea name="comment" cols="100" rows="8" id="comment" class="bodytext"></textarea><br/><br/>
    <input type="submit" name="submit" value="submit" />
    </fieldset>
    </form>

IMN logo majestic logo threadwatch logo seochat tools logo