php mail/contact form

Discussion in 'Free Hosting' started by eurisk52, Jul 14, 2012.

Thread Status:
Not open for further replies.
  1. eurisk52

    eurisk52 New Member

    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I have tried both making and downloaded templets that have a contact form in them and still i can't receive any emails when i test them out i'm on x10's free hosting the form says it sends but when i check for emails there's nothing. I have used both gmail address and at x10's elementfx account and i have still got no where with it. So anyway it is a html5 web site .I am not the best or even claim to know php code but here what i'm using. Can someone please help me.

    Here is the html code for emails

    <!-- form -->
    <h2>Contact Form</h2>
    <script type="text/javascript" src="js/form-validation.js"></script>
    <form id="contactForm" action="#" method="post">
    <fieldset>
    <div>
    <label>Name</label>
    <input name="name" id="name" type="text" class="form-poshytip" title="Enter your full name" />
    </div>
    <div>
    <label>Email</label>
    <input name="email" id="email" type="text" class="form-poshytip" title="Enter your email address" />
    </div>
    <div>
    <label>Website</label>
    <input name="web" id="web" type="text" class="form-poshytip" title="Enter your website" />
    </div>
    <div>
    <label>Comments</label>
    <textarea name="comments" id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
    </div>


    <!-- send mail configuration -->
    <input type="hidden" value="myemail@gmail.com" name="to" id="to" />
    <input type="hidden" value="myemail@gmail.com" name="from" id="from" />
    <input type="hidden" value="From torn wordpress online" name="subject" id="subject" />
    <input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
    <!-- ENDS send mail configuration -->

    <p><input type="button" value="SEND" name="submit" id="submit" /></p>
    </fieldset>
    <p id="error" class="warning">Message</p>
    </form>
    <p id="success" class="success">Thanks for your comments.</p>
    <!-- ENDS column -->


    and here is the send mail php

    <?php
    /**
    *
    *
    *
    *
    **/

    //vars
    $subject = $_POST['subject'];
    $to = explode(',', $_POST['to'] );

    $from = $_POST['email'];

    //data
    $msg = "NAME: " .$_POST['name'] ."<br>\n";
    $msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
    $msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
    $msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";

    //Headers
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8\r\n";
    $headers .= "From: <".$from. ">" ;


    //send for each mail
    foreach($to as $mail){
    mail($mail, $subject, $msg, $headers);
    }

    ?>
     
    Last edited: Jul 14, 2012
  2. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    You cannot send mail from any email address that doesn't belong to your hosting account. This is to prevent phishing and spam. Your script tries to send from the user's account (the value they enter into the email field on the form); because that address doesn't belong to your hosting account, the mail will be discarded silently by the outbound spam filter. You can use the ReplyTo header field to control where reply mail is sent, but the From field must be an account you own.
     
  3. eurisk52

    eurisk52 New Member

    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    So i need to replace email address in blue with one from x10's website?

    <!-- send mail configuration -->
    <input type="hidden" value="myemail@gmail.com" name="to" id="to" />
    <input type="hidden" value="myemail@gmail.com" name="from" id="from" />
    <input type="hidden" value="From torn wordpress online" name="subject" id="subject" />
    <input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
    <!-- ENDS send mail configuration -->
     
  4. Dead-i

    Dead-i x10Hosting Support Ninja Community Support

    Messages:
    6,084
    Likes Received:
    367
    Trophy Points:
    83
    No - you can just remove this line from your code to prevent it from trying to use a different email address:

    PHP:
    $headers .= "From: <".$from">" ;
     
  5. eurisk52

    eurisk52 New Member

    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    OK i took the $headers out of the php code and it didn't do the trick

    php code as it is now.
    <?php
    /**
    *
    *
    *
    *
    **/

    //vars
    $subject = $_POST['subject'];
    $to = explode(',', $_POST['to'] );

    $from = $_POST['email'];

    //data
    $msg = "NAME: " .$_POST['name'] ."<br>\n";
    $msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
    $msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
    $msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";

    //Headers
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8\r\n";


    //send for each mail
    foreach($to as $mail){
    mail($mail, $subject, $msg, $headers);
    }

    ?>
     
    Last edited: Jul 14, 2012
  6. eurisk52

    eurisk52 New Member

    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Ok i think i've tryed everything to get this contact form to work could someone help me to make a new one that works on here all i need is the name,email address and message and a mailer to send it with this is a html5 web site. Thanks
     
    Last edited: Jul 15, 2012
  7. wellebit

    wellebit New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Dear friend, this script will working on here. Only you must edit html section to personalize look of youre contact form. In PHP code you have all need instructions. Greetengs! :smile:

    ...............................................................................................................................................................................

    <?php
    // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!

    $yourEmail = "YOUR EMAIL"; // the email address you wish to receive these mails through
    $yourWebsite = "WEBSITE NAME"; // the name of your website
    $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
    $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
    $requiredFields = "name,email,comments"; // names of the fields you'd like to be required as a minimum, separate each field with a comma


    // DO NOT EDIT BELOW HERE
    $error_msg = null;
    $result = null;

    $requiredFields = explode(",", $requiredFields);

    function clean($data) {
    $data = trim(stripslashes(strip_tags($data)));
    return $data;
    }
    function isBot() {
    $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");

    foreach ($bots as $bot)
    if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
    return true;

    if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
    return true;

    return false;
    }

    if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isBot() !== false)
    $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];

    // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
    // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
    $points = (int)0;

    $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur", "content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");

    foreach ($badwords as $word)
    if (
    strpos(strtolower($_POST['comments']), $word) !== false ||
    strpos(strtolower($_POST['name']), $word) !== false
    )
    $points += 2;

    if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
    $points += 2;
    if (isset($_POST['nojs']))
    $points += 1;
    if (preg_match("/(<.*>)/i", $_POST['comments']))
    $points += 2;
    if (strlen($_POST['name']) < 3)
    $points += 1;
    if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
    $points += 2;
    // end score assignments

    foreach($requiredFields as $field) {
    trim($_POST[$field]);

    if (!isset($_POST[$field]) || empty($_POST[$field]))
    $error_msg .= "Please fill in all the required fields and submit again.\r\n";
    }

    if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
    $error_msg .= "The name field must not contain special characters.\r\n";
    if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
    $error_msg .= "That is not a valid e-mail address.\r\n";
    if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+):)(\d+))?\/?/i', $_POST['url']))
    $error_msg .= "Invalid website url.\r\n";

    if ($error_msg == NULL && $points <= $maxPoints) {
    $subject = "Automatic Form Email";

    $message = "You received this e-mail message through your website: \n\n";
    foreach ($_POST as $key => $val) {
    $message .= ucwords($key) . ": " . clean($val) . "\r\n";
    }
    $message .= "\r\n";
    $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
    $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
    $message .= 'Points: '.$points;

    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
    $headers = "From: $yourEmail\n";
    $headers .= "Reply-To: {$_POST['email']}";
    } else {
    $headers = "From: $yourWebsite <$yourEmail>\n";
    $headers .= "Reply-To: {$_POST['email']}";
    }

    if (mail($yourEmail,$subject,$message,$headers)) {
    if (!empty($thanksPage)) {
    header("Location: $thanksPage");
    exit;
    } else {
    $result = 'Your mail was successfully sent.';
    $disable = true;
    }
    } else {
    $error_msg = 'Your mail could not be sent this time. ['.$points.']';
    }
    } else {
    if (empty($error_msg))
    $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
    }
    }
    function get_data($var) {
    if (isset($_POST[$var]))
    echo htmlspecialchars($_POST[$var]);
    }
    ?>

    <!DOCTYPE html>
    <title>Contact Form</title>
    <meta charset="utf-8" />

    <!--[if IE]><style>#header h1 a:hover{font-size:75px;}</style><![endif]-->
    </head>
    <body>
    <div class="main-container">
    <header>
    <h1>Youre site</h1>
    </header>
    </div>
    <div class="main-container"></div>
    <div class="main-container">
    <div class="container1">
    <div class="box">
    <div class="content">
    <h1>Contact Us</h1>
    <?php
    if ($error_msg != NULL) {
    echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>";
    }
    if ($result != NULL) {
    echo '<p class="success">'. $result . "</p>";
    }
    ?>

    <form action="<?php echo basename(__FILE__); ?>" method="post">
    <noscript>
    <p><input type="hidden" name="nojs" id="nojs" /></p>
    </noscript>



    <br />
    <p>
    <input type="text" name="name" id="name" value="<?php get_data("name"); ?>" size="22" />
    <label for="name"><small>Name (required)</small></label>
    </p>
    <p>
    <input type="text" name="email" id="email" value="<?php get_data("email"); ?>" size="22" />
    <label for="email"><small>Mail (required)</small></label>
    </p>
    <p>
    <textarea name="comments" cols="70" rows="20" id="comments"><?php get_data("comments"); ?>
    </textarea>
    <label for="comments" style="display:none;"><small>Comment (required)</small></label>
    </p>
    <p>
    <input name="submit" type="submit" id="submit" value="Submit Form" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> />
    &nbsp;
    <input name="reset" type="reset" id="reset" tabindex="5" value="Reset Form" />
    </p>
    </form>

    <br>
    </div>
    <div class="clear"></div>
    </div>


    </div>
    <div class="main-container">
    </div>

    <div class="callout"></div>
    <footer>
    <p class="tagline_left">Copyright &copy; 2012 - All Rights Reserved - <a href="#">Domain Name</a> </p>
    </footer>
    </div>
    </body>
    </html>
     
  8. misson

    misson Community Paragon Community Support

    Messages:
    2,572
    Likes Received:
    72
    Trophy Points:
    48
    Please use
    PHP:
    , [html] or [codetags (as appropriateto separate and format code.

    [
    quote="eurisk52, post: 891613"]I have tried both making and downloaded templets that have a contact form in them and still i can't receive any emails when i test them out i'm on x10's free hosting the form says it sends but when i check for emails there's nothing.[/QUOTE]
    Make sure you check your junk mail folderAlsodelivery form X10 is sometimes slowI've seen messages get stuck in the mail queue for a month (though hopefully that particular issue was fixed).

    Does anyone else find run-on sentences exhausting?

    In the original script, since configuration data is placed in the form, it can be changed by malicious users. This means someone can use it to spam anyone, which will get your e-mail account (and likely X10) blocked by mail servers. Don'
    do that to X10.

    Note that the original script was vulnerable to e-mail header injectionbut the removal of the [c]$headers .= "From: <".$from">" ;[/cline fixed it.

    [
    quote="wellebit, post: 891694"][PHP]
        if (
    isBot() !== false)
    [/QUOTE]
    isBot only returns boolean values, so there's no need to compare with false. More than that, it doesn't use different falsey values for different (unlike e.g. strpos).

    Note that this can be simplified by using filter_var.
     
    Last edited: Jul 15, 2012
Thread Status:
Not open for further replies.

Share This Page