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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    33
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Can't Activation Email to Send?...Strange?

    Here is a script I have setup for user registration on a website of mine. I can't get the activation e-mail to send to the user. It worked the very first time I signed up with an email account under the sites same domain (ie me@thesite.com) But ever since I won't send out the activation email. I can go in the Admin Panel and activate the accounts manually. I am not a pro with PHP so let me know if you see something I don't. If you need any other piece of code let me know. Thanks for the help guys.


    Code:
    <?
    define('IN_RAFS', true);
    include "./sessions.php";
    include 'includes/header.php';
    
    $page = "Register";
    $adsense = "no";
    if ( $_SESSION['username'] != NULL ) {
            header("Location: index.php");
    }
    else {
    //        $username = ereg_replace("[^A-Za-z0-9]", "", strtolower(strip_tags($_POST['username'])));
            $password = sql_sanitize($_POST['password']);
            $cpassword = sql_sanitize($_POST['cpassword']);
            $enpassword = md5(base64_encode(md5($password)));
            $email = sql_sanitize($_POST['email']);
            $cemail = sql_sanitize($_POST['cemail']);
            $username = $email;
            $robotkey = sql_sanitize($_POST['rokey']);
            $fullname = sql_sanitize($_POST['fullname']);
            $street = sql_sanitize($_POST['street']);
            $city = sql_sanitize($_POST['city']);
            $state = sql_sanitize($_POST['state']);
            $zip = sql_sanitize($_POST['zip']);
            $referral = sql_sanitize($_POST['referral']);
            $item = sql_sanitize($_POST['item']);
            $ip = sql_sanitize($_SERVER['REMOTE_ADDR']);
            $time = time();
            $key = md5($time);
            $date = date("dgdijmzy");
    		$birthday_month = sql_sanitize($_POST['birthday_month']);
    		$birthday_day = sql_sanitize($_POST['birthday_day']);
    		$birthday_year = sql_sanitize($_POST['birthday_year']);
            $sid = session_id();
            if ( $sid != NULL ) {
                    $get = "SELECT `key` FROM `robot` WHERE `sid` = '$sid'";
                    $rkey =  @mysql_result(mysql_query($get), 0);
            }
            else {
            }
            if (isset($_GET['email'])) {
                                    if (isset($_GET['referral'])) {
                                            $referral = $_GET['referral'];
                    $referral_email = "SELECT `email` FROM `users` WHERE `id` = '$referral'";
                    $referral_email2 =  @mysql_result(mysql_query($referral_email), 0);
                                    $referral_text = "<BR>You are being referred by <B>" . $referral_email2 . "</B>";
                                    }
                                    else {
                                            $referral = 0;
                                    }
                    $tvars = array(
                            'EMAIL' => $_GET['email'],
    						'ITEM' => $_GET['item'],
                                                    'REFERRAL' => $referral,
                                                    'REFERRAL_EMAIL' => $referral_text,
                            'SID' => $sid
                            );
    
                    pparse('register_form');
    					include 'includes/footer.php';
                    exit;
            }
            if ($username != NULL && $password != NULL && $email != NULL && $robotkey != NULL && $email == $cemail && $password == $cpassword && $fullname != NULL && $street != NULL && $city != NULL && $state != NULL && $zip != NULL) {
                    $sqlsid = session_id();
                    $exists = mysql_query("SELECT * from users WHERE username='$username' or email='$email'");
                    $user_exists = mysql_fetch_array($exists);
                    $ipcheck = mysql_query("SELECT * from users WHERE ip='$ip'");
                    $ip_exists = mysql_fetch_array($ipcheck);
                    echo $_SESSION["autamationcode"];
    //                if ( $user_exists == "0" && $ip_exists == "0" && $robotkey == $rkey ) {
                      if ( $user_exists == "0" && $robotkey == $rkey ) {
                             $sql = "INSERT INTO users (id, username, password, email, ip, account, active, name, street, city, state, zip, referral, status, item)"."VALUES ('NULL', '$username', '$enpassword', '$email', '$ip', '0', '$key', '$fullname', '$street', '$city', '$state', '$zip', '$referral', '1', '$item')";
                            mysql_query($sql);
                            $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                            mysql_query($clearsid);
                            $uid = mysql_query("SELECT id from users WHERE username='$username'");
                            $u = mysql_result($uid, 0);
                            $message = "Thank your for registering! You're just one step away from being registered. Please check the e-mail you provided during registration. You were sent an activation link, just visit it and your account will be active and ready to go!";                
                            $tvars = array(
                                           'message' => $message);
                            pparse('message_body');
                            mail($email, "Welcome to " . $domain, "Thank you for registering at " . $domain . "!\n\nBefore you can get started, you need to activate your account, use the link below to do so\n\nhttp://" . $domain . "/activate.php?id=" . $u . "&k=" . $key . "\n\nOnce activated, you can login to your account with the following details:\n\nUsername: " . $username . "\nPassword: " . $password . "\n\nIf you have any problems please contact us.\n\nThanks,\n" . $domain, "From: " . $domain . " <support@" . $domain . ">");
                    }
                    elseif ( $robotkey != $rkey ) {
    						$back_link = "register.php?item=" . $_POST['item'] . "&email=" . $_POST['email'] . "&referral=" . $_POST['referral'];
                            $message = "Please make sure you typed the signup key properly.<br /><br />Click <a href=\"" . $back_link . "\">here</a> to go back.";
                            $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                            mysql_query($clearsid);
                            $tvars = array(
                                           'message' => $message);
                            pparse('message_body');
                    }
                    elseif ( $user_exists != "0" ) {
    						$back_link = "register.php?item=" . $_POST['item'] . "&email=" . $_POST['email'] . "&referral=" . $_POST['referral'];
                            $message = "Sorry but either your username or e-mail are already in use.<br /><br />Click <a href=\"" . $back_link . "\">here</a> to go back.";
                            $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                            mysql_query($clearsid);
                            $tvars = array(
                                           'message' => $message);
                            pparse('message_body');
                    }
            }
            elseif ( $_POST == NULL ) {
    
                            $tvars = array(
                                    'email' => $_GET['email'],
                                    'cemail' => $_GET['email'],
    								'ITEM' => $_GET['item'],
                                    'REFERRAL' => $referral,
                                    'REFERRAL_EMAIL' => $referral_text,
                                    'SID' => $sid
                                    );
    
                    pparse('register_form');
            }
            elseif ( $username != NULL && $password != NULL && $email != NULL && $cpassword != NULL && $cemail != NULL && $password != $cpassword ) {
                    $back_link = "register.php?item=" . $_POST['item'] . "&email=" . $_POST['email'] . "&referral=" . $_POST['referral'];
    				$message = "Your passwords do not match.<br /><br />Click <a href=\"" . $back_link . "\">here</a> to go back.";
                    $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                    mysql_query($clearsid);
                    $tvars = array(
                                   'message' => $message);
                    pparse('message_body');
            }
            elseif ( $username != NULL && $password != NULL && $email != NULL && $cpassword != NULL && $cemail != NULL && $email != $cemail ) {
                    $back_link = "register.php?item=" . $_POST['item'] . "&email=" . $_POST['email'] . "&referral=" . $_POST['referral'];
    				$message = "Your email does not match.<br /><br />Click <a href=\"" . $back_link . "\">here</a> to go back.";
                    $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                    mysql_query($clearsid);
                    $tvars = array(
                                   'message' => $message);
                    pparse('message_body');
            }
            elseif ( $_POST != NULL && $username == NULL or $password == NULL or $email == NULL or $cpassword == NULL or $cemail == NULL or $fullname == NULL or $street == NULL or $city == NULL or $state == NULL or $zip == NULL ) {
                    $back_link = "register.php?item=" . $_POST['item'] . "&email=" . $_POST['email'] . "&referral=" . $_POST['referral'];
    				$message = "Please fill in all required fields before submitting.<br /><br />Click <a href=\"" . $back_link . "\">here</a> to go back.";
                    $clearsid = "DELETE FROM `robot` WHERE `sid` = '$sid'";
                    mysql_query($clearsid);
                    $tvars = array(
                                   'message' => $message);
                    pparse('message_body');
            }
            //mysql_close($connect);
    	
    }
    
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You have a complete absense of error checking on all of your MySQL queries. How do you know if your queries worked or not? Your script certainly won't tell you.

    You should also check the mail() function's return value; it will be false if it failed.

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    33
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    You have a complete absense of error checking on all of your MySQL queries. How do you know if your queries worked or not? Your script certainly won't tell you.

    You should also check the mail() function's return value; it will be false if it failed.
    Thanks, I will play around testing the mail function a little better with a few if statements.

    But I am not sure how I go about error checking on the MySQL queries? Any ideas, or a quick example would be nice. Keep in mind I am not an expert code, and this is just a script a paid for. Thanks


  •  

    Posting Permissions

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