trouble with Email Script
Posted: Thu Mar 12, 2009 3:01 pm
hello,
i've run into a bit of trouble with my email script after a new user has registered to my site. i moved my registration from to the home page, which also includes a login form for current users... my problem: if a new user registers their info and there are no errors, the info is inserted into my database, but no confirmation email is sent to $_POST['email'] --the new user's email. i'd imagine it has something to do with both login and new registration forms being on the same page, but i can't figure it out, any suggestions? thank you!
i've run into a bit of trouble with my email script after a new user has registered to my site. i moved my registration from to the home page, which also includes a login form for current users... my problem: if a new user registers their info and there are no errors, the info is inserted into my database, but no confirmation email is sent to $_POST['email'] --the new user's email. i'd imagine it has something to do with both login and new registration forms being on the same page, but i can't figure it out, any suggestions? thank you!
Code: Select all
// if no errors, insert the details into the database
if (!$error) {
$insertSQL = sprintf("INSERT INTO userTable (user_id, username, password, register_date, email) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['register_date'], "defined", 'NOW()'),
GetSQLValueString($_POST['email'], "text"));
mysql_select_db($database_connUser, $connUser);
$Result1 = mysql_query($insertSQL, $connUser);
if (!$Result1 && mysql_errno() == 1062) {
$error['username'] = 'Either ' . $_POST['username'] . ' is already in use by another member.';
$error['email'] = 'OR ' . $_POST['email'] . ' is already a registered email account with us.';
} elseif (mysql_error()) {
$error['dbError'] = 'Sorry, there was a problem with the information. Please try again.';
} else {
$insertGoTo = "newuserConfirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
if (array_key_exists('Sign Up', $_POST)) {
$headers = "From: me<me@my.com>";
$to = $_POST['email']; // user email
$subject = 'You are now registered with shareyourdiscount.com';
// build message
$message = "Welcome to shareYOURdiscount.com!\r\n\r\n";
// limit line length to 70 characters
$message = wordwrap($message, 70);
$mailSent = mail($to, $subject, $message, $headers);
}
header(sprintf("Location: %s", $insertGoTo));
}
}
}
if (isset($_POST['password'])) { $_POST['password'] = sha1($_POST['password']); }
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (array_key_exists('doLogin', $_POST)) {
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "userprofile.php";
$MM_redirectLoginFailed = "loginfailedindex.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_connUser, $connUser);
$LoginRS__query=sprintf("SELECT username, password FROM userTable WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $connUser) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
}
?>