Hi, this is my logon/register script and recieved an error.
Instead of users logging in with an email adrress , I let them choose any logon id they want. i modded the script and put a LOGON_ID textbox and changed the script a little. Now there is an error. It is not sending an activation email. If i register i can logon with my own logon id, but i have to manually activate the account. It simply wont send the email.
Heres Register.php
<?php
# Script 16.6 - register.php
// This is the registration page for the site.
require_once ('includes/config.inc.php');
$page_title = 'Register';
include ('includes/header.html');
if (isset($_POST['submitted'])) { // Handle the form.
require_once (MYSQL);
// Trim all the incoming data:
$trimmed = array_map('trim', $_POST);
// Assume invalid values:
$fn = $ln = $e = $lid = $p = FALSE;
// Check for a first name:
if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) {
$fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']);
} else {
echo '<p class="error">Please enter your first name!</p>';
}
// Check for a last name:
if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) {
$ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']);
} else {
echo '<p class="error">Please enter your last name!</p>';
}
// Check for an email address:
if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) {
$e = mysqli_real_escape_string ($dbc, $trimmed['email']);
} else {
echo '<p class="error">Please enter a valid email address!</p>';
}
// Check for a logon id:
if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['logon_id'])) {
$lid = mysqli_real_escape_string ($dbc, $trimmed['logon_id']);
} else {
echo '<p class="error">Please enter a preferred logon id!</p>';
}
// Check for a password and match against the confirmed password:
if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) {
if ($trimmed['password1'] == $trimmed['password2']) {
$p = mysqli_real_escape_string ($dbc, $trimmed['password1']);
} else {
echo '<p class="error">Your password did not match the confirmed password!</p>';
}
} else {
echo '<p class="error">Please enter a valid password!</p>';
}
if ($fn && $ln && $e && $lid && $p) { // If everything's OK...
// Make sure the logon id is available:
$q = "SELECT user_id FROM users WHERE logon_id='$lid'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (mysqli_num_rows($r) == 0) { // Available.
// Create the activation code:
$a = md5(uniqid(rand(), true));
// Add the user to the database:
$q = "INSERT INTO users (email, logon_id, pass, first_name, last_name, active, registration_date) VALUES ('$e', '$lid', SHA1('$p'), '$fn', '$ln', '$a', NOW() )";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
// Send the email:
$body = "Thank you for registering at <CBJ NETWORKS>. To activate your account, please click on this link:\n\n";
$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";
mail($trimmed['email'], 'Registration Confirmation', $body, 'From: chabet12@roadrunner.com');
// Finish the page:
echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>';
include ('includes/footer.html'); // Include the HTML footer.
exit(); // Stop the page.
} else { // If it did not run OK.
echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
}
} else { // The email address is not available.
echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>';
}
} else { // If one of the data tests failed.
echo '<p class="error">Please re-enter your passwords and try again.</p>';
}
mysqli_close($dbc);
} // End of the main Submit conditional.
?>
<h1>Register</h1>
<form action="register.php" method="post">
<fieldset>
<p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p>
<p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p>
<p><b>Email Address:</b>
<input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /></p>
<p><b>LOGON ID:</b> <input type="text" name="logon_id" size="20" maxlength="20" value="<?php if (isset($trimmed['logon_id'])) echo $trimmed['logon_id']; ?>" /></p>
<p><b>Password:</b>
<input type="password" name="password1" size="20" maxlength="20" />
<small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p>
<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Register" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php // Include the HTML footer.
include ('includes/footer.html'); ?>
Here the error email it sent to me.:
<p>An error occurred in script 'C:\inetpub\wwwroot\auth\register.php' on line 79: mail(): SMTP server response: 550 5.7.1 Unable to relay
<br />Date/Time: 10-28-2011 02:54:21
<br /><pre>Array
(
[GLOBALS] => Array
*RECURSION*
[_POST] => Array
(
[first_name] => test
[last_name] => test
[email] => cjjohnson73@yahoo.com
[logon_id] => test
[password1] => test
[password2] => test
[submit] => Register
[submitted] => TRUE
)
[_GET] => Array
(
)
[_COOKIE] => Array
(
[PHPSESSID] => koqkb5t6gno5m10viejmil8m14
[PBack] => 0
[sessionid] => 1fd019cf-7597-42a8-a5a9-b852f3ac0255
[cadata] => "0PCJztaQvSAgLbNwdJUaYYxoTvR 0O1m4K5SubHL83rDxlmUyxDfwO/E0IJmSIsTiHtmk7Gg9uMUaZlmasDEj8F/uEz7p 8gziIOl4w=="
[UserContext] => c8a338c07ebb4433a8cd71cc631c1774
)
[_FILES] => Array
(
)
[page_title] => Register
[_SESSION] => Array
(
)
[dbc] => mysqli Object
(
[affected_rows] => 1
[client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
[client_version] => 50008
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 0
[host_info] => localhost via TCP/IP
[info] =>
[insert_id] => 19
[server_info] => 5.1.57-community
[server_version] => 50157
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 193
[warning_count] => 0
)
[trimmed] => Array
(
[first_name] => test
[last_name] => test
[email] => cjjohnson73@yahoo.com
[logon_id] => test
[password1] => test
[password2] => test
[submit] => Register
[submitted] => TRUE
)
[p] => test
[lid] => test
[e] => cjjohnson73@yahoo.com
[ln] => test
[fn] => test
[q] => INSERT INTO users (email, logon_id, pass, first_name, last_name, active, registration_date) VALUES ('cjjohnson73@yahoo.com', 'test', SHA1('test'), 'test', 'test', '680bb1fdeaea7a4d573ddc2d9c019375', NOW() )
[r] => 1
[a] => 680bb1fdeaea7a4d573ddc2d9c019375
[body] => Thank you for registering at <CBJ NETWORKS>. To activate your account, please click on this link:
http://192.168.1.2/activate.php?x=cjjohnson73%40yahoo.com&y=680bb1fdeaea7a4d573ddc2d9c019375
)
</pre>
</p>