Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Contact Script - Action Script failure

Options
  • 09-04-2007 1:55am
    #1
    Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭


    Hey,

    OK well iv been using a Contact Us script on several sites (on different servers) but for some reason, it wont work on a new website (on a new server) that im developing. The code checks for empty fields, and if email addresses are valid (coded by a chap I know who codes "mods" for the IPB software). I advanced the basic contact script ages ago to include the CAPTCHA image thingy, and it worked fine.

    The same script is deployed on a new server, with different fields (as its a different form). It seems to detect errors (such as empty fields or invalid emails) but when the form is OK it says its sent, but the email never arrives. Have I done something wrong in the code that I cant see, or could this be a server issue?

    [php]<?php
    $sendfromname = $_POST;
    $sendfrom = $_POST;
    $s_code = $_POST;
    $to = "sully@thenet2k.com";
    $subject = $_POST;
    $msg = $_POST;
    $message = "Below is the result of your feedback form.\n
    \n\n\nName: $sendfromname\n\nEmail Address: $sendfrom\n\n\nOther Comments:\n\n$msg\n\n
    \n";

    /* Checks whether everything is filled out and if it isn't tells them */
    if (empty($sendfromname) || empty($sendfrom) || empty($subject))
    {
    @header(&quot;Location: http://somesite.com/error2.html");
    }

    session_start();

    //Encrypt the posted code field and then compare with the stored key

    if(md5($_POST) != $_SESSION)
    {
    die("Incorrect Security Code. Go back, and re-enter the new code.");
    }

    /* Checks to see if the email is valid or not */
    if (!check_email($sendfrom))
    {
    @header(&quot;Location: http://somesite.com/error.html");

    }
    else
    {
    if (@mail($to, $subject, $message, "From: ".$sendfrom))
    {
    @header(&quot;Location: http://somesite.com/thanks.html");
    }
    else
    {
    die ("An error has occured. Please try again or contact the webmaster.");
    }
    }

    /* Checks to see if the email is valid or not - the work behind the command */
    /* Written By: Dean (D-Scripting [http://www.dscripting.com])*/
    function check_email($email)
    {
    if (!ereg("[^@]{1,64}@[^@]{1,255}", $email))
    {
    return false;
    }

    $ea = explode('@', $email);
    $la = explode('.', $ea[0]);

    for ($i=0; $i<count($la); $i++)
    {
    if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $la[$i]))
    {
    return false;
    }
    }

    if (!ereg("^\[?[0-9\.]+\]?$", $ea[1]))
    {
    $da = explode('.', $ea[1]);
    if (count($da) < 2)
    {
    return false;
    }

    for ($i=0; $i<count($da); $i++)
    {
    if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $da[$i]))
    {
    return false;
    }
    }
    }

    return true;
    }



    ?>[/php]

    Im sure you noticed the use of die() and location() to print errors. I hate this way of doing things as I think its messy coding, but I was once told that no other way was posssible. Is this true? Are there ways of printing the error to the same page, or does it have to be done in the ways used above?

    Thanks for your assistance.


Advertisement