3

我正在一个小型网站上工作,该网站要求用户注册一个帐户,然后向他们发送一封电子邮件,其中包含验证帐户的详细信息。单击验证电子邮件中的链接后,该帐户应该处于活动状态并且用户应该能够登录。我从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**
4

3 回答 3

3

您必须为 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 服务器,您应该配置此服务器以发送邮件,如我所述的 xampp 示例

于 2017-05-15T17:21:22.730 回答
1

我建议如果您已经有一个网络托管帐户,您可以使用您的 Gmail 或 Yahoo a/c 在线尝试。在桌面上设置电子邮件既繁琐又耗时。

于 2013-02-25T21:22:05.230 回答
0

创建您的网页包含(登录页面、注册页面和主页),要求:

1- 对用户名、电子邮件、密码、重新输入密码、性别和出生日期数据的注册表进行验证。

2-使用用户名和密码验证登录表单数据并创建登录会话。

3-建立数据库连接以存储用户信息并验证登录数据。

4- 仅在登录成功时才授予主页和访问权限。

5- 从主页注销并销毁用户会话。

moyasar_22@hotmail.com

于 2016-02-17T13:37:54.597 回答