Hi,
I have a registration script that works with mysql. Everything works great but I would like an email notification when a new user signs up and I can't seem to get it working. Here is my original script without the mail function. My question is how can I achieve this and where in the script should it go?
Any help would be so appreciated. Thanks!
if (isset($_POST['submit'])) { # if form has been submitted
/* check they filled in what they supposed to,
passwords matched, username
isn't already taken, etc. */
if (!$_POST['uname'] | !$_POST['passwd'] | !$_POST['passwd_again'] | !$_POST['email'] | !$_POST['realname']) {
die('You did not fill in a required field.');
}
# check if username exists in database.
if (!get_magic_quotes_gpc()) {
$_POST['uname'] = addslashes($_POST['uname']);
}
$name_check = q("SELECT username FROM " . $db_prefix . "users WHERE username = '".$_POST['uname']."'");
$name_checkk = nr($name_check);
if ($name_checkk != 0) {
die('Sorry, the username: <strong>'.$_POST['uname'].'</strong> is already taken, please pick another one.');
}
# check passwords match
if ($_POST['passwd'] != $_POST['passwd_again']) {
die('Passwords did not match.');
}
# check e-mail format
if (!preg_match("/.*@.*..*/", $_POST['email']) | preg_match("/(<|>)/", $_POST['email'])) {
die('Invalid e-mail address.');
}
# no HTML tags in username, website, location, password
$_POST['uname'] = strip_tags($_POST['uname']);
$_POST['passwd'] = strip_tags($_POST['passwd']);
$_POST['website'] = strip_tags($_POST['website']);
$_POST['realname'] = strip_tags($_POST['realname']);
/* the rest of the information is optional, the only thing we need to
check is if they submitted a website,
and if so, check the format is ok. */
if ($_POST['website'] != '') {
$_POST['website'] = str_replace("http://","",$_POST['website']);
$_POST['website'] = str_replace("https://","",$_POST['website']);
$_POST['website'] = str_replace("ftp://","",$_POST['website']);
}
# Encrypt password and add new user to database.
$_POST['passwd'] = md5($_POST['passwd']);
$regdate = date('m/d/Y');
$insert = sprintf("INSERT INTO " . $db_prefix . "users (username, password, regdate, email,realname,website) VALUES (%s,%s,%s,%s,%s,%s)",
GetSQLValueString($_POST['uname'],'text'),
GetSQLValueString($_POST['passwd'],'text'),
GetSQLValueString($regdate,'text'),
GetSQLValueString($_POST['email'],'text'),
GetSQLValueString($_POST['realname'],'text'),
GetSQLValueString($_POST['website'],'text'));
$add_member = q($insert);