簡體   English   中英

PHP注冊和登錄表單和電子郵件驗證/郵件服務器設置

[英]PHP registration and login forms&email verification/Mail server setup

我正在建立一個小網站,要求用戶注冊一個帳戶,之后會向他們發送一封電子郵件,其中包含驗證帳戶的詳細信息。 單擊驗證電子郵件中的鏈接后,該帳戶應處於活動狀態,用戶應該能夠登錄。 我從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()。 PHP在541行

目前我有一些問題: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服務器,你應該配置這個服務器發送郵件,如我所說的xampp示例

我建議如果您已經擁有一個網絡托管帳戶,您只需使用Gmail或Yahoo a / c在線試用即可。 在桌面上設置電子郵件非常繁忙且耗時。

創建您的網頁包含(登錄頁面,注冊頁面和主頁面)以及要求:

1-對用戶名,電子郵件,密碼,重新輸入密碼,性別和生日數據的注冊表格進行驗證。

2,使用用戶名和密碼驗證登錄表單數據並創建登錄會話。

3-建立數據庫連接以存儲用戶信息並驗證登錄數據。

只有登錄成功時才限制主頁面和訪問權限。

5-從主頁面注銷並銷毀用戶會話。

moyasar_22@hotmail.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM