I made a working registration script which is used for android devices. The only thing which is left,is sending an email to the user that welcomes him ie "Welcome to the app..." and so on. However,I am stuck with this,as no email is sent.
Here is my script.
<?php
require "init.php";
header('Content-type: application/json');
$email = $_POST['email'];
$user_name = $_POST['user_name'];
$user_pass = $_POST['user_pass'];
$msg = "Congratulations. You are now registered to the most amazing app
ever!";
$passwordEncrypted = sha1($user_pass);
if($email && $user_name && $user_pass){
$sql_query = "select * from user_info WHERE email ='".mysqli_real_escape_string($con, $email)."' and user_name ='".mysqli_real_escape_string($con, $user_name)."'";
$result = mysqli_query($con, $sql_query);
$results = mysqli_num_rows($result);
if ($results){
$don = array('result' =>"fail","message"=>"Email or username exists.");
}else{
$sql_query = "insert into user_info values('$email','$user_name','$passwordEncrypted');";
if(mysqli_query($con,$sql_query)){
$don = array('result' =>"success","message"=>"Successfully registered!Well done");
mail("$email","Well done",$msg);
}
}
} if(!$email || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$don = array('result' =>"fail","message"=>"Please enter a valid email");
}else if(!$user_name){
$don = array('result' =>"fail","message"=>"Please enter your username");
}else if(!$user_pass || (strlen($user_pass)<8 || (!preg_match('`[A-Za-z0-9]`', $user_pass)))){
$don = array('result' =>"fail","message"=>"Password must contain 8 letters or more with at least one capital letter ");
}
echo json_encode($don);
?>
Any ideas on that one?
Thanks.