Я знаю, что подобные вопросы были заданы здесь. Я искал, но они не очень актуальны для моей проблемы и решения, которое я ищу.
У меня есть этот скрипт PHP, который я использую для регистрации пользователей на моем сайте. Он предназначен только для отправки подтверждающего / подтверждающего электронного письма владельцу регистрации, но я хочу, чтобы оно также отправляло мне, администратору, электронное письмо с уведомлением о том, что кто-то зарегистрировал свою информацию. Я не знаю, как этого добиться.
Вот код:
<?php
include 'dbc.php';
$err = array();
if($_POST['doRegister'] == 'Register')
{
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
require_once('recaptchalib.php');
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("<h3>Image Verification failed!. Go back and try again.</h3>" .
"(reCAPTCHA said: " . $resp->error . ")");
}
if(empty($data['first_name']) || strlen($data['first_name']) < 4)
{
$err[] = "ERROR - Please enter your first name";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['last_name']) || strlen($data['last_name']) < 4)
{
$err[] = "ERROR - Please enter your last name";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['tel']) || strlen($data['tel']) < 6)
{
$err[] = "ERROR - Please enter your phone number";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['address']) || strlen($data['address']) < 6)
{
$err[] = "ERROR - Please enter your contact address";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['city']) || strlen($data['city']) < 3)
{
$err[] = "ERROR - Please enter your city of residence";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['state']) || strlen($data['state']) < 3)
{
$err[] = "ERROR - Please enter your state of residence";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['country']) || strlen($data['country']) < 3)
{
$err[] = "ERROR - Please choose your country of residence";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['birth_date']) || strlen($data['birth_date']) > 10)
{
$err[] = "ERROR - Please choose your date of birth";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['gender']) || strlen($data['gender']) < 4)
{
$err[] = "ERROR - Please enter your gender";
//header("Location: register.php?msg=$err");
//exit();
}
if(empty($data['description']) || strlen($data['description']) < 10)
{
$err[] = "ERROR - Please describe yourself";
//header("Location: register.php?msg=$err");
//exit();
}
// Validate User Name
if (!isUserID($data['user_name'])) {
$err[] = "ERROR - Invalid user name. It can contain alphabet, number and underscore.";
//header("Location: register.php?msg=$err");
//exit();
}
// Validate Email
if(!isEmail($data['usr_email'])) {
$err[] = "ERROR - Invalid email address.";
//header("Location: register.php?msg=$err");
//exit();
}
// Check User Passwords
if (!checkPwd($data['pwd'],$data['pwd2'])) {
$err[] = "ERROR - Invalid Password or mismatch. Enter 6 chars or more";
//header("Location: register.php?msg=$err");
//exit();
}
$user_ip = $_SERVER['REMOTE_ADDR'];
// stores sha1 of password
$sha1pass = PwdHash($data['pwd']);
// Automatically collects the hostname or domain like example.com)
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
// Generates activation code simple 4 digit number
$activ_code = rand(1000,9999);
$usr_email = $data['usr_email'];
$user_name = $data['user_name'];
/************ USER EMAIL CHECK ************************************
This code does a second check on the server side if the email already exists. It
queries the database and if it has any existing email it throws user email already exists
*******************************************************************/
$rs_duplicate = mysql_query("select count(*) as total from users where user_email='$usr_email' OR user_name='$user_name'") or die(mysql_error());
list($total) = mysql_fetch_row($rs_duplicate);
if ($total > 0)
{
$err[] = "ERROR - The username/email already exists. Please try again with different username and email.";
//header("Location: register.php?msg=$err");
//exit();
}
/***************************************************************************/
if(empty($err)) {
$sql_insert = "INSERT into `users`
(`first_name`,`last_name`,`user_email`,`pwd`,`tel`,`address`,`city`,`state`,`birth_date`,`gender`,`description`,`date`,`users_ip`,`activation_code`,`country`,`user_name`
)
VALUES
('$data[first_name]','$data[last_name]','$usr_email','$sha1pass','$data[tel]','$data[address]','$data[city]','$data[state]','$data[birth_date]','$data[gender]','$data[description]'
,now(),'$user_ip','$activ_code','$data[country]','$user_name'
)
";
mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
$user_id = mysql_insert_id($link);
$md5_id = md5($user_id);
mysql_query("update users set md5_id='$md5_id' where id='$user_id'");
// echo "<h3>Thank You</h3> We received your submission.";
if($user_registration) {
$a_link = "*****ACTIVATION LINK*****\n
http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code
";
} else {
$a_link =
"Your account is *PENDING APPROVAL* and will be soon activated by the administrator.
";
}
$message =
"Hello $data[first_name] $data[last_name], \n
Thank you for your interest in Kisil Entertainment Network. Either you or someone representing you submitted your registration details on our website; http://$host$path. If you neither submitted nor authorized anyone to submit on your behalf, please kindly ignore and immediately delete this message. If you either submitted or authorized someone to submit on your behelf, click on the link below to activate your account and complete your registeration with Kisil Entertainment Network. Here are your login details...\n
User ID: $user_name
Email: $usr_email \n
Passwd: $data[pwd] \n
Click on this link to activate your account $a_link.
If you cannot click on the link, go to http://$host$path/activate.php and paste this activation code: $activ_code into the activation box.
You are welcome to the Kisil Entertainment Network family.
Kind regards,
Kisil Entertainment Network
http://$host$path
Nigeria's No.1 Entertainment Network. /n
______________________________________________________
NOTE: THIS IS AN AUTOMATICALLY GENERATED RESPONSE.
***DO NOT REPLY TO THIS EMAIL****
";
send_mail( 'Kisil Entertainment Network.<[email protected]>',
$usr_email,
'Activate your account',
$message);
header("Location: thankyou.php");
exit();
}
}
foreach($_GET as $key => $value) {
$get[$key] = filter($value); //get variables are filtered.
}
if ($_POST['doLogin']=='Login')
{
foreach($_POST as $key => $value) {
$data[$key] = filter($value); // post variables are filtered
}$user_email = $data['usr_email'];
$pass = $data['pwd'];if (strpos($user_email,'@') === false) {
$user_cond = "user_name='$user_email'";
} else {
$user_cond = "user_email='$user_email'";
}$result = mysql_query("SELECT `id`,`pwd`,`first_name`,`last_name`,`approved`,`user_level` FROM users WHERE
$user_cond
AND `banned` = '0'
") or die (mysql_error());
$num = mysql_num_rows($result);
// Match row found with more than 1 results - the user is authenticated.
if ( $num > 0 ) {
list($id,$pwd,$first_name,$last_name,$approved,$user_level) = mysql_fetch_row($result);
if(!$approved) {
//$msg = urlencode("Account not activated. Please check your email for activation code");
$err[] = "Account not activated. Please check your email for activation code";
//header("Location: login.php?msg=$msg");
//exit();
}
//check against salt
if ($pwd === PwdHash($pass,substr($pwd,0,9))) {
if(empty($err)){
// this sets session and logs user in
session_start();
session_regenerate_id (true); //prevent against session fixation attacks.
// this sets variables in the session
$_SESSION['user_id']= $id;
$_SESSION['user_name'] = $first_name;
$_SESSION['user_level'] = $user_level;
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
//update the timestamp and key for cookie
$stamp = time();
$ckey = GenKey();
mysql_query("update users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'") or die(mysql_error());
//set a cookie
if(isset($_POST['remember'])){
setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_key", sha1($ckey), time()+60*60*24*COOKIE_TIME_OUT, "/");
setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*COOKIE_TIME_OUT, "/");
}
header("Location: myaccount.php");
}
}
else
{
//$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
$err[] = "Invalid Login. Please try again with correct user email and password.";
//header("Location: login.php?msg=$msg");
}
} else {
$err[] = "Error - Invalid login. No such user exists";
}
}
?>
Просто добавьте свой почтовый идентификатор в BCC сценария php mail. Затем вы получаете почту для регистрации пользователя.
Других решений пока нет …