Jump to content

Email admin after user registers


matrixx

Recommended Posts

Hello I have a simple php registration to gain access to a member's only section of a website. I would like the admin emailed after a user registers. I would like the email to say "firstname lastname has just registered. Please login to approve." I receive an email but it's blank. I've tried to define $message but when I do it messes up the message that is sent to the registrant. PLEASE help.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
</head>
<?php

$link = mysql_connect('localhost:/tmp/mysql5.sock', 'xxxxx', 'xxxxx');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//mysql_close($link);
if (!mysql_select_db('db', $link)) {
echo 'Could not select database';
exit;
}

$username = $HTTP_POST_VARS["username"];
$send = true;
$password = $HTTP_POST_VARS["password"];
$firstname = $HTTP_POST_VARS["firstname"];
$lastname = $HTTP_POST_VARS["lastname"];
$address = $HTTP_POST_VARS["address"];
$city = $HTTP_POST_VARS["city"];
$state = $HTTP_POST_VARS["state"];
$zipcode = $HTTP_POST_VARS["zipcode"];
$email = $HTTP_POST_VARS["email"];
$phone = $HTTP_POST_VARS["phone"];
$profession = $HTTP_POST_VARS["profession"];

$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$email_for_admin = "admin@server.com";
// Formulate Query
// This is the best way to perform a SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT username FROM users WHERE username = '%s' ",
mysql_real_escape_string($username));
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while ($row = mysql_fetch_assoc($result)) {

$send = false;
}
$url = 'register.php?username=' . $username . '&firstname=' . $firstname . '&lastname=' . $lastname . '&address=' . $address . '&city=' . $city . '&state=' . $state . '&zipcode=' . $zipcode . '&email=' . $email . '&phone=' . $phone . '&profession=' . $profession;
if ($send == false) {
print "<META HTTP-EQUIV='Refresh' content='0;URL=" . $url . "'>";
} else {
$query = "insert into users (username, password, role) values ('" . $username . "', '" . $password . "', 'user')";
mysql_query($query, $link);
$query = sprintf("SELECT member_id FROM users where username = '%s' ",
mysql_real_escape_string($username));
$result = mysql_query($query);
$memberid = '';
while ($row = mysql_fetch_assoc($result)) {

$memberid = $row['member_id'];
}

$query = "insert into members (member_id, firstname, lastname, address, city, state, zipcode, phone, email, profession) values (" . $memberid . ", '" . $firstname . "', '" . $lastname . "', '" . $address . "', '" . $city . "', '" . $state . "', '" . $zipcode . "', '" . $phone . "', '" . $email . "', '" . $profession . "')";
mysql_query($query, $link);

$subject = 'Welcome';
$body = 'Thank you for registering. Please make sure you check back with us frequently for updates and announcements. You will have access to the member area after your registration is approved by the administrator.';
$headers = 'From: mail@server.com' . "\r\n" .
'Reply-To: mail@server.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();


mail($email_for_admin, "new member", $message,
"From: \"server.com\" <auto-reply@$host>\r\n" .
"X-Mailer: PHP/" . phpversion());
}
?>
<body>
<div class="main">
<div class="blok_header">
<div class="header">
 <div class="clr"></div>
</div>
<div class="clr"></div>
<div class="body">
<div class="body_bg">
 <h2>
<div id="content">
<h2>Registration Complete</h2>
<p> <table width="610" border="0" cellspacing="0" cellpadding="15">
 <tr>
	 <td valign="top"></td>
 </tr>
 <table width="610" border="0" cellspacing="5" cellpadding="5">

 <?php
if ($send == true) {
 if (mail($email, $subject, $body, $headers)) {
?>
<tr>
	 <td>Thank you for registering. Please check your registered email for a confirmation. You will have access to the member's area after your registration is approved by the administrator.
		 <br><br><a href="memberlogin.php">Click Here to LOGIN</a><br />
		 <br><br><a href="index.html">Click Here to go HOME </a><br />	
	 </td>
 </tr>
<?php
}
}
?>
 </table>
 <table width="610" border="0" cellspacing="5" cellpadding="5">
 <tr>
	 <td > </i></b></td>
 </tr>
 </table>
</td>
</tr>
</table>
 </div> </p>
 <div class="clr"></div>
</div>
<div class="clr"></div>
</div>
</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.