Saturday 20 January 2018

mysql - PHP and SMTP not working together









Im
following a tutorial on how to register a user through an email authorization. Im having
some trouble on SMTP. Im not sure why, but the script will not send the email. I dont
know if its an issue with the SMTP or what. The tutorial is from 2009 so it may not be
exactly compatible with the newest build of php. Does anyone see anything that is
causing the issue?




echo "

Register

";

$submit
= filter_input(INPUT_POST, 'submit');

//form data

$fullname = strip_tags (filter_input(INPUT_POST, 'fullname'));
$username =
strtolower(strip_tags (filter_input(INPUT_POST, 'username')));
$password =
strip_tags(filter_input(INPUT_POST, 'password'));
$repeatpassword =
strip_tags(filter_input(INPUT_POST, 'repeatpassword'));
$date =
date("Y-m-d");
$email = strtolower(strip_tags (filter_input(INPUT_POST,
'email')));

if ($submit)
{

//open
database

$connect=mysql_connect("localhost","root","myrealpasswordwouldgohere");

mysql_select_db("phplogin");

$namecheck = mysql_query("SELECT
username FROM users WHERE username='$username'" );
$count =
mysql_num_rows($namecheck);

if($count!=0)
{

die("Username already taken, please choose another");


}

//check for
existence
if($fullname&&$username&&$password&&$repeatpassword)
{

if ($password==$repeatpassword)
{
//check char length of username
and fullname
if (strlen($username)>25||strlen($fullname)>25)

{

echo "Length of username or full name is too long!";

}
else
{
//check password length
if (strlen
($password)>25 || strlen ($password)<6)
{
echo "Password
must be between 6 and 25 characters";
}
else


{
$password = md5($password);
//register user


//generate random number
$random =
rand(23456789,98765432);


$queryreg =
mysql_query("INSERT INTO users VALUES
('','$fullname','$username','$password','$email','$date','$random','0')");

die ("You have been registered! Check your email to activate your account to activate
your account.");


$lastid =
mysql_insert_id();

//send activation email
$to =
$email;
$subject = "Activate your Account";
$headers = "From:
ryansinclair14@gmail.com";
$server = "smtp.gmail.com";


ini_set("SMTP","smtp.gmail.com");


$body = "

Hello $fullname,\n\n
You need to activate you account with the link
below:

http://localhost/academy/loginsession/activate.php?id=$lastid&code=$random
\n\n

Thanks!
";

//function to
send email

mail($to, $subject, $body, $headers);

die("You have been registered! Check your email to activate your
account.");



}




}







}
else echo "Your passwords do not
match";


}
else echo "Please fill in
all fields!";




}


?>





method='POST'>
















































Your full name:




choose a username:

type='text' name='username' value=''>


Choose a password:




Repeat your password:

name='repeatpassword'>


Email:

name='email'>



value='Register'>



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...

Blog Archive