0

My php file for registering

<?php
    require("password.php");
    $connect = mysqli_connect("localhost", "root", "", "accounts");

    $first_name = $_POST["first_name"];
    $last_name = $_POST["last_name"];
    $email = $_POST["email"];
    $password = $_POST["password"];

     function registerUser() {
        global $connect, $first_name, $last_name, $email, $password;
        $passwordHash = password_hash($password, PASSWORD_DEFAULT);
        $statement = mysqli_prepare($connect, "INSERT INTO users (first_name, last_name, email, password, hash, active) VALUES (?, ?, ?, ?, 123, 0)");
        mysqli_stmt_bind_param($statement, "ssss", $first_name, $last_name, $email, $passwordHash);
        mysqli_stmt_execute($statement);
        mysqli_stmt_close($statement);

        // Send registration confirmation link (verify.php)
        $to      = $email;
        $subject = 'Account Verification ( Name.com )';
        $message_body = '
        Hello '.$first_name.',
        Thank you for signing up!
        Please click this link to activate your account:
        http://localhost/accounts/verify.php?email='.$email.'&hash='.'123';  
        mail( $to, $subject, $message_body );
    }

    function emailAvailable() {
        global $connect, $email;
        $statement = mysqli_prepare($connect, "SELECT * FROM users WHERE email = ?"); 
        mysqli_stmt_bind_param($statement, "s", $email);
        mysqli_stmt_execute($statement);
        mysqli_stmt_store_result($statement);
        $count = mysqli_stmt_num_rows($statement);
        mysqli_stmt_close($statement); 
        if ($count < 1){
            return true;            
        }else {
            return false; 
        }
    }

    $success = '';
    $response = array();
    $response["success"] = false;

    if (emailAvailable()){
        registerUser();
        mysqli_set_charset($con,"utf8");
        $response["success"] = true;
        }

    echo json_encode($response);
?>

After adding the code

    // Send registration confirmation link (verify.php)
    $to      = $email;
    $subject = 'Account Verification ( Name.com )';
    $message_body = '
    Hello '.$first_name.',
    Thank you for signing up!
    Please click this link to activate your account:
    http://localhost/accounts/verify.php?email='.$email.'&hash='.'123';  
    mail( $to, $subject, $message_body );

there is no response from my application from

    $response["success"] = true;
    }

    echo json_encode($response);

however $response["success"] = false; still works and outputs a false value.

I am looking for a way to implement the mailing system in such a way that it does not affect the $response["success"] = true;

Will appreciate any guidance from anyone that can help thank you!

David
  • 1
  • 1
  • What do you mean by "there is no response from my application form"? Do you not get any output at all? Then there might be an error generated, which is not being displayed. See https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851 – Progman Dec 30 '17 at 10:33

1 Answers1

0

you need to configure your php.ini file and comment the following code

/*[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = localhost
; smtp_port = 25
*/

/*; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost
*/ 

if it didn't work in local host. You can make it live by taking free hosts from link below https://www.000webhost.com

comment me if it didn't work.

Alish Manandhar
  • 110
  • 1
  • 11
  • Hi Alish, Thanks for the quick response, however the problem I am currently facing is that $response["success"] = true; is not responding after adding the email code, however sending email is fine. – David Dec 30 '17 at 07:42