我正在一个小型网站上工作,该网站要求用户注册一个帐户,然后向他们发送一封电子邮件,其中包含验证帐户的详细信息。单击验证电子邮件中的链接后,该帐户应该处于活动状态并且用户应该能够登录。我从registration.php(注册)、login.php(登录)和verify.php(验证帐户激活)中提供了3个PHP片段!!我正在使用 WAMP 服务器创建数据库并根据表
注意:这是我在注册页面上收到的唯一错误。
警告:mail():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\wamp\www\ONLINE BANKING\registration 中使用 ini_set()。第 541 行的 php
目前我有几个问题: 1. 我正在使用 hmailserver,但我不确定如何设置它 2. 我需要监控用户何时添加到数据库中(我假设这只是在单击电子邮件验证链接)
请告诉我我做错了什么以及如何解决
**REGISTRATION.PHP**
<div id="wrap">
<!-- start PHP code -->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with root .
mysql_select_db("registrations") or die(mysql_error()); // Select registration database.
$email="";
if( isset($_POST['fullname']) // Is the name field being posted; it does not matter whether it's empty or filled.
&& // This is the same as the AND in our statement; it allows you to check multiple statements.
!empty($_POST['fullname']) // Verify if the field name is not empty
AND isset($_POST['email']) // Is the email field being posted; it does not matter if it's empty or filled.
&& // This is the same as the AND in our statement; it allows you to check multiple statements.
!empty($_POST['email']) ) // Verify if the field email is not empty
{
$fullname = mysql_real_escape_string($_POST['fullname']);
$email = mysql_real_escape_string($_POST['email']);
}
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)){
// Return Error - Invalid Email
$msg = 'The email you have entered is invalid, please try again.';
}else{
// Return Success - Valid Email
$msg = 'Your account has been created, <br /> please verify it by clicking the activation link that has been send to your email.';
}
$hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.
$PIN = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable.
$to = $email; // Send email to our user
$subject = 'Signup | Verification'; // Give the email a subject
$from="info@bfs.com";
$message = 'Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by clicking the url below.
------------------------
echo $_POST["UserID"];
PIN: '.$PIN.'
------------------------
Please click this link to activate your account:
http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
'; // Our message above including the link
$headers = 'From:noreply@yourwebsite.com' . "\r\n"; // Set from headers
mail($to, $subject, $message, $headers); // Send our email //Line 541
?>
<!-- stop PHP Code -->
</div>
**LOGIN.PHP**
<div id="wrap">
<!-- start PHP code -->
<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); // Connect to database server(localhost) with UserID and PIN.
mysql_select_db("registrations") or die(mysql_error()); // Select registration database.
if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['PIN']) && !empty($_POST['PIN'])){
$UserID = mysql_escape_string($_POST['name']);
$PIN = mysql_escape_string(md5($_POST['PIN']));
$search = mysql_query("SELECT UserID, PIN, active FROM users WHERE UserID='".$UserID."' AND PIN='".$PIN."' AND active='1'") or die(mysql_error());
$match = mysql_num_rows($search);
if($match > 0){
$msg = 'Login Complete! Thanks';
}else{
$msg = 'Login Failed!<br /> Please make sure that you enter the correct details and that you have activated your account.';
}
}
?>
<!-- stop PHP Code -->
<?php
if(isset($msg)){ // Check if $msg is not empty
echo '<div class="statusmsg">'.$msg.'</div>'; // Display our message and add a div around it with the class statusmsg
} ?>
</div>
**VERIFY.PHP**