我正在开发一个小型网站,该网站要求用户注册一个帐户,之后会向他们发送一封电子邮件,其中包含验证帐户的详细信息。点击验证电子邮件中的链接后,帐户应处于活动状态,用户应能够登录。我提供了registration.PHP(注册(、login.PHP(登录(和verify.PHP(验证帐户激活(中的3个PHP片段!!我正在使用WAMP服务器创建数据库,并根据表
注意:这是我在注册页面上收到的唯一错误。
警告:mail((:无法连接到位于"的邮件服务器;localhost";端口25,验证您的";SMTP";以及";smtp_port";在php.ini中设置或在C:''wamp''www''ONLINE BANKING''registration.php的541 行使用ini_set((
目前我有一些问题: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**
您必须为sendig邮件设置服务器
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服务器,您应该配置该服务器以发送邮件,如我所说的示例,例如
我建议,如果你已经有了一个网络托管帐户,你可以简单地使用你的Gmail或Yahoo帐户在线尝试。在桌面上设置电子邮件既繁忙又耗时。
创建您的网页包含(登录页、注册页和主页(,要求:
1-对用户名、电子邮件、密码、重新键入密码、性别和出生日期数据的注册表进行验证。
2-使用用户名验证登录表单数据&密码并创建登录会话。
3-建立数据库连接以存储用户信息并验证登录数据。
4-仅在登录成功的情况下才允许访问主页。
5-从主页注销并销毁用户会话。
moyasar_22@hotmail.com