Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email form not sending. But mailtest.php is.

    Hey all, New to the forum, So hello to all.

    I am having some issues with my mail form not sending. I added a test email page with this code and it worked, Here is the code that worked.

    mailtest.php
    PHP Code:
    <?php
    mail
    ('MYEMAIL@Domain.com','Test mail','The mail function is working!');
    echo 
    'Mail sent!';
    ?>
    But when I add this code to my page and rename the page, the email and info doesnt get sent.

    Here is my code. (inserted in html page but renamed apply.php)

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

    $yourEmail "MYEMAIL@Domain.com"// (this is switched to my email) the email address you wish to receive these mails through
    $yourWebsite "My Website"// the name of your website
    $maxPoints 4// max points a person can hit before it refuses to submit - recommend 4


    function isBot() {
        
    $bots = array("Indy""Blaiz""Java""libwww-perl""Python""OutfoxBot""User-Agent""PycURL""AlphaServer""T8Abot""Syntryx""WinHttp""WebBandit""nicebot");
        
    $isBot false;
        
        foreach (
    $bots as $bot)
        if (
    strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
            
    $isBot true;

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

    if (
    $_SERVER['REQUEST_METHOD'] == "POST") {
        if (
    isBot())
            exit(
    "Bots not allowed.</p>");

        function 
    clean($data) {
            
    $data trim(stripslashes(strip_tags($data)));
            return 
    $data;
        }
        
        
    // 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""****""ejaculate""***""felatio""fellatio""****""fuk""fuks""gangbang""gangbanged""gangbangs""hotsex""hardcode""jism""jiz""orgasim""orgasims""orgasm""orgasms""phonesex""phuk""phuq""porn""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");
        
    $exploits = array("content-type""bcc:""cc:""document.cookie""onclick""onload""javascript");

        foreach (
    $badwords as $word)
            if (
    strpos($_POST['comments'], $word) !== false)
                
    $points += 2;
        
        foreach (
    $exploits as $exploit)
            if (
    strpos($_POST['comments'], $exploit) !== false)
                
    $points += 2;
        
        if (
    strpos($_POST['comments'], "http://") === true || strpos($_POST['comments'], "www.") === true)
            
    $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

        
    if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
            
    $error_msg .= "Name, e-mail and comments are required fields. \n";
        } elseif (
    strlen($_POST['name']) > 15) {
            
    $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n";
        } elseif (!
    ereg("^[A-Za-z' -]*$"$_POST['name'])) {
            
    $error_msg .= "The name field must not contain special characters. \n";
        } elseif (!
    ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) {
            
    $error_msg .= "That is not a valid e-mail address. \n";
        } elseif (!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.";
        
        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) . ": $val \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 \r\n";
                
    $headers  .= "Reply-To: {$_POST['email']}";
            } else {
                
    $headers   "From: $yourWebsite <$yourEmail> \r\n";
                
    $headers  .= "Reply-To: {$_POST['email']}";
            }

            if (
    mail($yourEmail,$subject,$message,$headers)) {
                echo 
    '<p>Your mail was successfully sent.</p>';
            } else {
                echo 
    '<p>Your mail could not be sent this time.</p>';
            }
        }
    }
    function 
    get_data($var) {
        if (isset(
    $_POST[$var]))
            echo 
    htmlspecialchars($_POST[$var]);
    }
    if (
    $error_msg != NULL) {
        echo 
    '<p><strong style="color: red;">ERROR:</strong><br />';
        echo 
    nl2br($error_msg) . "</p>";
    }
    ?>


    <form action="apply.php" method="post" ENCTYPE="multipart/form-data">
    <noscript>
            <p><input type="hidden" name="nojs" id="nojs" /></p>
    </noscript>
    <p>
        <label for="name">Name:</label><br /> 
            <input type="text" name="name" id="name" value="<?php get_data("name"); ?>" size="30"/></p>
        <p>
        <label for="email">E-mail:</label> <br />
            <input type="text" name="email" id="email" value="<?php get_data("email"); ?>" size="30" /><br />
        </p>
        <p>
        <label for="name">Number:</label> <br />
            <input type="text" name="number" id="number" value="<?php get_data("number"); ?>" /></p>
        <p>
        <label for="url">Position you are applying for:</label><br /> 
            <select name="position" id="position" >
          <option selected="selected">accounting+finance</option>
          <option>admin / office</option>
          <option>arch / engineering</option>
          <option>art / media / design</option>
          <option>biotech / science</option>
          <option>business / mgmt</option>
          <option>customer service</option>
          <option>education</option>
          <option>food / bev / hosp</option>
          <option>general labor</option>
          <option>government</option>
          <option>human resources</option>
          <option>internet engineers</option>
          <option>legal / paralegal</option>
          <option>manufacturing</option>
          <option>marketing / pr / ad</option>
          <option>medical / health</option>
          <option>nonprofit sector</option>
          <option>real estate</option>
          <option>retail / wholesale</option>
          <option>sales / biz dev</option>
          <option>salon / spa / fitness</option>
          <option>security</option>
          <option>skilled trade / craft</option>
          <option>software / qa / dba</option>
          <option>systems / network</option>
          <option>technical support</option>
          <option>transport</option>
          <option>tv / film / video</option>
          <option>web / info design</option>
          <option>writing / editing</option>
        </select></p>
        <p>
        <label for="location">Upload your resume:</label><br />
        <span class="style1">(Must be in .doc, .rtf, .txt or 
        .pdf format)</span><br />
            <input type="file" name="upload" size="30"/><br />
        </p>
        <p>
        <label for="name">Credit Score:</label> <br />
            <input type="text" name="score" id="score" value="<?php get_data("score"); ?>" size="30"/></p>
        <h3 class="style2" style="width: 224px">Your application will not be 
        accepted and marked as incomplete without your real credit score. To obtain 
        your credit score free Click on the banner below.</h3>
        <p>
        <img alt="" height="27" src="credit.png" width="288" /></p>
        <p>

        <label for="comments">Comments:</label><br />
            <textarea name="comments" id="comments" rows="5" cols="20"><?php get_data("comments"); ?></textarea><br />
        </p>
    <p>
        <input type="submit" name="submit" id="submit" value="Send" />
    </p>
    </form>
    I have been fighting this for around 3 hrs now, looking and search for possible reasons and solutions but cannot find anything.

    Any help would be greatly appreciated.

    Thanks in advance.
    Last edited by WebbieWorks; 01-06-2010 at 08:15 PM. Reason: Added PHP wrapper

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,539
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    blush ... I love your bad word list.

    I would start removing your various sections, one at a time
    until it starts to work. Start with the isBot test, and keep
    eliminating all of those "odd tests" that you're doing. One of
    them must always be failing.

    That much validation is mind boggling.
    Wouldn't a simple captcha (or Re-Captcha) be enough?

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just grabbed the code from

    Code:
    http://www.jemjabella.co.uk/php-scripts-php-mail-form
    I never did a email form with code, I always used a program, but it wouldnt work for this type form,

    I will start removing it all 1 by 1 and see what happens. Very much appreciate the quick response

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I did alot of editing on this and I got the form to email, but its not emailing all the submitted info.

    Here is what I did. I added a mailer.php and edited my code to suit, All it is sending is the name.

    Mailer.php
    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "MYEMAIL@gmail.com";
    $subject "Form Submission";
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $number_field $_POST['number'];
    $position_field $_POST['position'];
    $upload_field $_POST['upload'];
    $score_field $_POST['score'];
    $comments_field $_POST['comments'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "blarg!";

    }
    ?>
    my code for form
    PHP Code:
    <form method="POST" action="mailer.php" ENCTYPE="multipart/form-data">
    <
    noscript>
            <
    p><input type="hidden" name="nojs" id="nojs" /></p>
    </
    noscript>
    <
    p>
        <
    label for="name">Name:</label><br /> 
            <
    input type="text" name="name" id="name" value="" size="30"/></p>
        <
    p>
        <
    label for="email">E-mail:</label> <br />
            <
    input type="text" name="email" id="email" value="" size="30" /><br />
        </
    p>
        <
    p>
        <
    label for="name">Number:</label> <br />
            <
    input type="text" name="number" id="number" value="" /></p>
        <
    p>
        <
    label for="url">Position you are applying for:</label><br /> 
            <
    select name="position" id="position" >
          <
    option selected="selected">accounting+finance</option>
          <
    option>admin office</option>
          <
    option>arch engineering</option>
          <
    option>art media design</option>
          <
    option>biotech science</option>
          <
    option>business mgmt</option>
          <
    option>customer service</option>
          <
    option>education</option>
          <
    option>food bev hosp</option>
          <
    option>general labor</option>
          <
    option>government</option>
          <
    option>human resources</option>
          <
    option>internet engineers</option>
          <
    option>legal paralegal</option>
          <
    option>manufacturing</option>
          <
    option>marketing pr ad</option>
          <
    option>medical health</option>
          <
    option>nonprofit sector</option>
          <
    option>real estate</option>
          <
    option>retail wholesale</option>
          <
    option>sales biz dev</option>
          <
    option>salon spa fitness</option>
          <
    option>security</option>
          <
    option>skilled trade craft</option>
          <
    option>software qa dba</option>
          <
    option>systems network</option>
          <
    option>technical support</option>
          <
    option>transport</option>
          <
    option>tv film video</option>
          <
    option>web info design</option>
          <
    option>writing editing</option>
        </
    select></p>
        <
    p>
        <
    label for="location">Upload your resume:</label><br />
        <
    span class="style1">(Must be in .doc, .rtf, .txt or 
        .
    pdf format)</span><br />
            <
    input type="file" name="upload" size="30"/><br />
        </
    p>
        <
    p>
        <
    label for="name">Credit Score:</label> <br />
            <
    input type="text" name="score" id="score" value="" size="30"/></p>
        <
    h3 class="style2" style="width: 224px">Your application will not be 
        accepted 
    and marked as incomplete without your real credit scoreTo obtain 
        your credit score free Click on the banner below
    .</h3>
        <
    p>
        <
    img alt="" height="27" src="credit.png" width="288" /></p>
        <
    p>

        <
    label for="comments">Comments:</label><br />
            <
    textarea name="comments" id="comments" rows="5" cols="20"></textarea><br />
        </
    p>
    <
    p>
        <
    input type="submit" name="submit" id="submit" value="Send" />
    </
    p>
    </
    form
    This is getting frustrating. I know it is something very simple but no matter what I try or read it is not working.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    So what information isn't being submitted? I'm going to guess its the file input. You need to handle that part differently. Simply getting the post value doesn't create an attachment automatically. And your $body variable has none of your post variables.

    PHP Code:
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message" 
    Of course you aren't going to see anything if variables don't exist. I guess thats what happens when you just copy and paste.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahhh, I knew it was something very simple. Very much apprecieted.

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    $name_field catches the POSTed variable in that code block above. $message doesn't exist, though. Not sure what the deal is with $email_field. It's set up to catch the data, though, I think.
    Are you a Help Vampire?

  • #8
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, Now I have the form emailing everything but the uploaded file. So thats a big step.

    Now just have to figure out how to attach the uploaded file to the email.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •