2013-02-25 20 views
2

我正在開發一個小型網站,該網站要求用戶註冊一個帳戶,然後向他們發送一封電子郵件,其中包含驗證該帳戶的詳細信息。點擊驗證電子郵件中的鏈接後,帳戶應該是積極的,用戶應該能夠登錄。 我已經從registration.php(註冊),login.php(登錄)和verify.php(驗證帳戶的激活)提供了3個PHP代碼段 !!我正在使用WAMP服務器創建數據庫,並按照表PHP註冊和登錄表單和電子郵件驗證/郵件服務器設置

注意:這是我在註冊頁面上收到的唯一錯誤。

警告:電子郵件():無法連接在本地主機"端口" 25至郵件服務器,驗證您的" SMTP "和" SMTP_PORT "設置在php.ini或C使用的ini_set():\ WAMP \ WWW \ ONLINE 1.我現在用的是hmailserver,但我不完全知道如何設置它 2.我需要給用戶時,監測:上線541

目前我有幾個問題銀行\和registration.php已被添加到數據庫中(我認爲這是電子郵件驗證鏈接被點擊後,才)

請告訴我什麼,我做錯了,這可怎麼固定

**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="[email protected]"; 
     $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:[email protected]' . "\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** 

回答

1

我建議,如果你已經有了託管帳戶網頁,你可以簡單地在網上嘗試使用Gmail或雅虎的A/C。在桌面上建立的電子郵件是忙碌和耗時。

+0

我已經有一個Web託管帳戶。但是,如何在用戶註冊電子郵件時通過我的雅虎電子郵件發送到用戶在註冊頁面中指定的任何電子郵件地址進行測試? – Kaos 2013-02-25 21:26:22

+1

這是一個漫長的過程!請檢查該鏈接,這個例子中,你會準備好去。 http://www.phpeasystep.com/phptu/24.html – Richie 2013-02-25 22:12:04

+0

謝謝,這是一個非常有用的鏈接。我假設到目前爲止,我的代碼沒有任何問題。(唯一不同的是,在你給我的鏈接中,有一個臨時數據庫,在單擊驗證電子郵件中的鏈接之後,註冊詳細信息將被存儲和傳輸。)我基本上只需要知道我是如何處理它是正確的以及有效 – Kaos 2013-02-25 23:09:26

0

創建自己的網頁中含有(登錄頁面,註冊頁面和主頁)與要求:

1用戶名,電子郵件,密碼,重新輸入密碼,性別和出生日期數據的登記表上應用驗證。

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

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

4限制到主頁面和僅當登錄成功時授予訪問權限。

5-從主頁面註銷並銷燬用戶會話。

[email protected]

2

你必須設置你的服務器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 
[email protected] 
auth_password=YourMailPass 

你的情況,你有WAMP的服務器,你應該配置此服務器發送郵件,因爲我的XAMPP例如說