0

i am creating a login and registration form with mysql and i need to the user when he submit i send to him an activation code for inbox in his registered email but when i clic submit in the register form i get this error : Undefined variable: INFO in C:\wamp\www\new loginregi\register.php on line 87

and this error: Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\new loginregi\register.php on line 87.

can anyone help me to fix these errors i need it to be fixed by tomorrow it is very important

this is the code of the:

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 name@server.tld!</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: noreply@youwebsitehere.co.uk');
                                            //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(); ?>
dev leb
  • 65
  • 1
  • 1
  • 8
  • You need to configure your WAMP setup properly or sending mails won't work. – Till Helge Mar 02 '13 at 19:41
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Madara's Ghost Mar 02 '13 at 19:45
  • @ middaparka first sir if they are informative for you that because you are familiar with php but iam new and i want to learn it but if the web developer are like you i regret for this choice second if i found the error and know how to fix it i would be here to read your comment anyway thanks for your comment – dev leb Mar 02 '13 at 19:48

1 Answers1

0

For the first error. I think perhaps you copied this code from somewhere:

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: noreply@youwebsitehere.co.uk');

And for your case replace $INFO['chatName'] with $username;

In the first line as you see , there's a variable named $INFO['chatname'] that it is not defined.

For your second error you must setup your local mail server. If you use windows, i recommend the below link:

Send Mail from localhost in Windows

MIIB
  • 1,849
  • 10
  • 21
  • thank MIIB FOR YOUR HELP YES YOU ARE RIGHT I copied because i need it to work for tomorrow but it is the first time for me with the sendig mail and i do not know how to fix it – dev leb Mar 02 '13 at 19:51
  • You should setup your mail server and for a beginner it is not easy. I recommend you use KMail php class for sending mail. You can google KMail php class and download it and read it's manual and documentation. It is easy to use. And edit $INFO['chatName'] to $username. – MIIB Mar 02 '13 at 19:57