...

View Full Version : Can't Activation Email to Send?...Strange?



WorldVision
12-08-2008, 11:44 PM
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.



<?
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);

}

?>

Fumigator
12-09-2008, 04:31 PM
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.

WorldVision
12-09-2008, 09:48 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum