#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2018
    Posts
    8
    Rep Power
    0

    Problems with PHP MySQL Login System


    Hello all,

    I'm trying to follow a tutorial - Create a Login System using PHP and MYSQL Database (with a forgot password function).

    I copied the source code and replicated the database and I seemed to get the site mostly working on my local development server. What didn't work was the sending of the confirmation emails. I guessed this might be to do with issues / Settings with my local WAMP set up, so I moved the project onto my live server, updating the database connection settings.

    However, it still isn't working properly. I have uploaded here:
    Sign-Up/Login Form

    The idea is that a new user registers and then a confirmation email is sent to the email address they registered. The user would then click on that link which gets sent to her email account and that would then validate that user (by changing the value assigned for validate next to that user).

    What appears to be happening is that the new user information is populating the appropriate table but an email is not being sent out to the entered address. The code is below. It seems like perhaps mail( $to, $subject, $message_body ); isn't working?

    The code relating to the the sending of the email is :

    PHP Code:
        $sql "INSERT INTO users (first_name, last_name, email, password, hash) " 
                
    "VALUES ('$first_name','$last_name','$email','$password', '$hash')";

        
    // Add user to the database
        
    if ( $mysqli->query($sql) ){

            
    $_SESSION['active'] = 0//0 until user activates their account with verify.php
            
    $_SESSION['logged_in'] = true// So we know the user has logged in
            
    $_SESSION['message'] =
                    
                     
    "Confirmation link has been sent to $email, please verify
                     your account by clicking on the link in the message!"
    ;

            
    // Send registration confirmation link (verify.php)
            
    $to      $email;
            
    $subject 'Account Verification ( clevertechie.com )';
            
    $message_body '
            Hello '
    .$first_name.',

            Thank you for signing up!  

            Please click this link to activate your account:

            http://localhost/login-system/verify.php?email='
    .$email.'&hash='.$hash;  //This is the message which is sent using the hashed strings in the link. It sends you through to verify page 

            
    mail$to$subject$message_body ); //This is the php mail function. It takes in the strings set and sends to that email address. 

            
    header("location: profile.php"); //in php we redirect using the header function (can create a function which does this or just using this)

        

    Happy to post the rest of the code for the index pages if it helps? Many thanks for reading.
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    Check the return value from mail() to see if it thinks it is working.

    But much better would be to use something like PHPMailer instead.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2018
    Posts
    8
    Rep Power
    0
    Thanks for the reply requinix.

    Hmmm. Yeah, I tried a simple script to test in mail() was working -
    PHP Code:
    <!-- test email to see if mail function is working-->

    <p>test page</p>

    <?php
    $to 
    "adamyounis@yahoo.com";
    $subject "Second TEst";
    $message "Hello world!";
    $headers "From: charlienick76@yahoo.co.uk" "\r\n" .
    "CC: somebodyelse@example.com";

    mail($to,$subject,$message,$headers);
    ?>
    But this didn't seem to work. I still got no email sent.

    Issues with my configuration files or something?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2018
    Posts
    8
    Rep Power
    0

    Thanks


    Originally Posted by requinix
    Check the return value from mail() to see if it thinks it is working.

    But much better would be to use something like PHPMailer instead.

    Okay - I'll give php Mailer a go. Thanks.
  8. #5
  9. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,896
    Rep Power
    9646
    Didn't see that post of yours from a week ago. It's visible now.

    Again, you need(ed) to check the return value from mail(). Also look at your server error log in case there's something relevant in there.

IMN logo majestic logo threadwatch logo seochat tools logo