2013-03-02 57 views
0

我正在用mysql創建一個登錄和註冊表單,當我提交給用戶時,我需要給他發送一封在他註冊郵箱中的收件箱的激活碼,但是當我在註冊表格中提交時,這個錯誤:未定義的變量:C:\ wamp \ www中的INFO \ line 87上的new loginregi \ register.php註冊問題php mysql

和此錯誤: 警告:mail():無法連接到「本地主機」端口25上的郵件服務器,請在php.ini中驗證您的「SMTP」和「smtp_port」設置,或在第87行的C:\ wamp \ www \ new loginregi \ register.php中使用ini_set()。

任何人都可以幫助我解決這些錯誤我需要明天修復它非常重要

這是其中的代碼:

register.php
<?php 
    //allow sessions to be passed so we can see if the user is logged in 
    ob_start(); 
    if(isset($_SESSION)){ 
     session_start(); 
    } 

    //connect to the database so we can check, edit, or insert data to our users table 
    $con = mysql_connect('localhost', 'root', '') or die(mysql_error()); 
    $db = mysql_select_db('loginTut', $con) or die(mysql_error()); 
    //include out functions file giving us access to the protect() function 
    include "./functions.php"; 
    ?> 
    <html> 
     <head> 
      <title>Login with Users Online Tutorial</title> 
      <link rel="stylesheet" type="text/css" href="style.css" /> 
     </head> 
     <body> 
      <?php 
      //Check to see if the form has been submitted 
      if(isset($_POST['submit'])){ 
       //protect and then add the posted data to variables 
       $username = protect($_POST['username']); 
       $password = protect($_POST['password']); 
       $passconf = protect($_POST['passconf']); 
       $email = protect($_POST['email']); 
       //check to see if any of the boxes were not filled in 
       if(!$username || !$password || !$passconf || !$email){ 
        //if any weren't display the error message 
        echo "<center>You need to fill in all of the required filds!</center>"; 
       }else{ 
        //if all were filled in continue checking 
        //Check if the wanted username is more than 32 or less than 3 charcters long 
        if(strlen($username) > 32 || strlen($username) < 3){ 
         //if it is display error message 
         echo "<center>Your <b>Username</b> must be between 3 and 32 characters long!</center>"; 
        }else{ 
         //if not continue checking 
         //select all the rows from out users table where the posted username matches the username stored 
         $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'"); 
         $num = mysql_num_rows($res); 
         //check if theres a match 
         if($num == 1){ 
          //if yes the username is taken so display error message 
          echo "<center>The <b>Username</b> you have chosen is already taken!</center>"; 
         }else{ 
          //otherwise continue checking 
          //check if the password is less than 5 or more than 32 characters long 
          if(strlen($password) < 5 || strlen($password) > 32){ 
           //if it is display error message 
           echo "<center>Your <b>Password</b> must be between 5 and 32 characters long!</center>"; 
          }else{ 
           //else continue checking 
           //check if the password and confirm password match 
           if($password != $passconf){ 
            //if not display error message 
            echo "<center>The <b>Password</b> you supplied did not math the confirmation password!</center>"; 
           }else{ 
            //otherwise continue checking 
            //Set the format we want to check out email address against 
            $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; 
            //check if the formats match 
            if(!preg_match($checkemail, $email)){ 
             //if not display error message 
             echo "<center>The <b>E-mail</b> is not valid, must be [email protected]!</center>"; 
            }else{ 
             //if they do, continue checking 
             //select all rows from our users table where the emails match 
             $res1 = mysql_query("SELECT * FROM `users` WHERE `email` = '".$email."'"); 
             $num1 = mysql_num_rows($res1); 
             //if the number of matchs is 1 
             if($num1 == 1){ 
              //the email address supplied is taken so display error message 
              echo "<center>The <b>E-mail</b> address you supplied is already taken</center>"; 
             }else{ 
              //finally, otherwise register there account 
              //time of register (unix) 
              $registerTime = date('U'); 
              //make a code for our activation key 
              $code = md5($username).$registerTime; 
              //insert the row into the database 
              $res2 = mysql_query("INSERT INTO `users` (`username`, `password`, `email`, `rtime`) VALUES('".$username."','".$password."','".$email."','".$registerTime."')"); 
              //send the email with an email containing the activation link to the supplied email address 
              mail($email, $INFO['chatName'].' registration confirmation', "Thank you for registering to us ".$username.",\n\nHere is your activation link. If the link doesn't work copy and paste it into your browser address bar.\n\nhttp://www.yourwebsitehere.co.uk/activate.php?code=".$code, 'From: [email protected]'); 
              //display the success message 
              echo "<center>You have successfully registered, please visit you inbox to activate your account!</center>"; 
             } 
            } 
           } 
          } 
         } 
        } 
       } 
      } 
      ?> 
      <div id="border"> 
       <form action="register.php" method="post"> 
        <table cellpadding="2" cellspacing="0" border="0"> 
         <tr> 
          <td>Username: </td> 
          <td><input type="text" name="username" /></td> 
         </tr> 
         <tr> 
          <td>Password: </td> 
          <td><input type="password" name="password" /></td> 
         </tr> 
         <tr> 
          <td>Confirm Password: </td> 
          <td><input type="password" name="passconf" /></td> 
         </tr> 
         <tr> 
          <td>Email: </td> 
          <td><input type="text" name="email" size="25"/></td> 
         </tr> 
         <tr> 
          <td colspan="2" align="center"><input type="submit" name="submit" value="Register" /></td> 
         </tr> 
         <tr> 
          <td colspan="2" align="center"><a href="login.php">Login</a> | <a href="forgot.php">Forgot Pass</a></a></td> 
         </tr> 
        </table> 
       </form> 
      </div> 
     </body> 
    </html> 
    <?php ob_end_flush(); ?> 
+0

您需要正確配置WAMP設置或發送郵件將無法正常工作。 – 2013-03-02 19:41:37

+0

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – 2013-03-02 19:45:49

+0

@ middaparka第一先生,如果他們是爲你提供信息,因爲你熟悉PHP,但IAM新,我想學習它,但如果Web開發人員像你一樣,我後悔這種選擇第二,如果我發現錯誤,並知道如何修復它我會在這裏閱讀您的評論感謝您的評論 – 2013-03-02 19:48:01

回答

0

對於第一個錯誤。我想也許你複製從什麼地方這樣的代碼:

mail($email, $INFO['chatName'].' registration confirmation', "Thank you for registering to us ".$username.",\n\nHere is your activation link. If the link doesn't work copy and paste it into your browser address bar.\n\nhttp://www.yourwebsitehere.co.uk/activate.php?code=".$code, 'From: [email protected]'); 

而對於你的情況與$username取代$INFO['chatName'];

在你看到的第一行中,有一個名爲$ INFO ['chatname']的變量,它沒有被定義。

對於第二個錯誤,您必須設置您的本地郵件服務器。如果你使用Windows,我建議以下鏈接:

Send Mail from localhost in Windows

+0

感謝MIIB爲您的幫助是的你是正確的我複製,因爲我需要它爲明天工作,但這是我第一次與sendig郵件,我做不知道如何修復它 – 2013-03-02 19:51:26

+0

你應該設置你的郵件服務器,對於初學者來說這並不容易。我建議你使用KMail php類來發送郵件。你可以谷歌KMail PHP類並下載它並閱讀它的手冊和文檔。它很容易使用。然後編輯$ INFO ['chatName']到$ username。 – MIIB 2013-03-02 19:57:15