PHP注册和登录表单&;电子邮件验证/邮件服务器设置
我正在一个小网站上工作,该网站要求用户注册一个帐户,然后会向他们发送一封电子邮件,详细说明如何验证该帐户。单击验证电子邮件中的链接后,帐户应处于活动状态,用户应能够登录。 我提供了来自registration.PHP(要注册)、login.PHP(要登录)和verify.PHP(要验证帐户的激活)的3个PHP代码段 !! 我正在使用WAMP服务器创建数据库和相应的表 注意:这是我在注册页面上收到的唯一错误 警告:mail():无法在“localhost”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP\u端口”设置,或在第541行的C:\wamp\www\ONLINE BANKING\registration.php中使用ini\u set() 目前我有几个问题: 1.我正在使用hmailserver,但我不确定如何设置它 2.我需要监视用户何时被添加到数据库中(我假设这只是在单击电子邮件验证链接之后) 请告诉我我做错了什么,以及如何解决这个问题PHP注册和登录表单&;电子邮件验证/邮件服务器设置,php,sql,wamp,mail-server,Php,Sql,Wamp,Mail Server,我正在一个小网站上工作,该网站要求用户注册一个帐户,然后会向他们发送一封电子邮件,详细说明如何验证该帐户。单击验证电子邮件中的链接后,帐户应处于活动状态,用户应能够登录。 我提供了来自registration.PHP(要注册)、login.PHP(要登录)和verify.PHP(要验证帐户的激活)的3个PHP代码段 !! 我正在使用WAMP服务器创建数据库和相应的表 注意:这是我在注册页面上收到的唯一错误 警告:mail():无法在“localhost”端口25连接到mailserver,请验证
**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**
**REGISTRATION.PHP**
**LOGIN.PHP**
我建议,如果你已经有了一个网络托管帐户,你可以简单地使用你的Gmail或Yahoo a/c在线试用。在桌面上设置电子邮件既繁忙又耗时。创建包含以下要求的网页(登录页、注册页和主页):
1-对用户名、电子邮件、密码、重新键入密码、性别和出生日期数据的注册表进行验证
2-验证使用用户名和密码登录表单数据,并创建登录会话
3-建立数据库连接以存储用户信息和验证登录数据
4-仅当登录成功时才授予主页和访问权限的限制
5-从主页注销并销毁用户会话
莫亚萨_22@hotmail.com您必须为发送邮件设置服务器
set mail function in php.ini file to sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t" if you use something like xampp
and then
set senmail.ini
smtp_server=smtp.gmail.com //example
smtp_port=587
auth_username=YourMail@gmail.com
auth_password=YourMailPass
在您的情况下,您有wamp服务器,您应该将此服务器配置为发送邮件,正如我在xampp示例中所述,我已经有了一个web托管帐户。但我如何测试当用户注册时,电子邮件是否会从我的雅虎电子邮件发送到用户在注册页面中指定的任何电子邮件地址?这是一个漫长的过程!请在此链接上查看此示例,您就可以开始了。谢谢,这是一个非常有用的链接。我假设到目前为止我的代码没有问题。(唯一的区别是,在你给我的链接中,有一个临时数据库,在点击验证电子邮件中的链接后,注册详细信息将被存储和传输。)我基本上只需要知道我的方式是否正确有效不,你做得不对。应该有两个表供临时用户使用,另一个表供实际确认其电子邮件地址的成员使用。这是一个完美的方法。