Jump to content

I have problem (Warning: mail() [function.mail]: SMTP server response)


Hany_h2004

Recommended Posts

I created system registration

 

---------------------------------------------------------------------------------------------

Features:

 

  • Encrypted passwords
    Email Validation
    Change Password
    Members List
    User Profiles

 

Ok lets start of with the SQL.

 

Run this query

 

CREATE TABLE `members` (

`id` int(11) NOT NULL auto_increment,

`username` varchar(30) NOT NULL default '',

`password` varchar(255) NOT NULL default '',

`email` varchar(55) NOT NULL default '',

`location` varchar(40) NOT NULL default 'N/A',

`userlevel` int(3) NOT NULL default '1',

`age` int(3) NOT NULL,

`sex` varchar(40) NOT NULL default 'N/A',

PRIMARY KEY (`id`)

) TYPE=MyISAM;

 

CREATE TABLE `verification` (

`id` int(11) NOT NULL auto_increment,

`username` varchar(30) NOT NULL default '',

`code` varchar(255) NOT NULL default '',

PRIMARY KEY (`id`)

) TYPE = MYISAM ;

 

Now we have the SQL lets start with the user system.

 

config.php

 

<? 

session_start(); //allows session

 

$conn = mysql_connect("localhost","USER","PASSWORD"); 

mysql_select_db(DBNAME) or die(mysql_error()); 

 

$logged = MYSQL_QUERY("SELECT * FROM `members` WHERE `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'"); 

$logged = mysql_fetch_array($logged); 

 

//some server details, don't edit!

$host = $_SERVER['HTTP_HOST'];

$self = $_SERVER['PHP_SELF'];

 

//change this to your site name

$sitename = "My Site";

 

//Send emails or not (email activation). 1 = true, 0 = false

$semail = "1";

 

?>

 

Change the connection and change your site name.

 

Now lets let people register

 

register.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

//checks if there trying to veriy there account

if(isset($_GET['verify'])) {

//gets the code and makes it safe

$code = addslashes($_GET['code']);

//gets the code from the database

$getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");

//counts the number of rows

$getcode = mysql_num_rows($getcode);

//if the ammount of rows is 0 the code does not exist

if($getcode == 0) { 

echo "Invalid verification code!"; 

//or if the code does exist we will activiate there account

else{

//get the data from the database

$getcode=mysql_query("SELECT * FROM `verification` WHERE `code` = '$code'");

//fetchs the data from the db

$dat = mysql_fetch_array($getcode);

//sets the users user level to 2 which means they can now use there account

$update = mysql_query("UPDATE `members` SET `userlevel` = '2' WHERE `username` = '".$dat['username']."'") or die(mysql_error());

//deletes the code as there is no use of it now

$delete = mysql_query("DELETE FROM `verification` WHERE code = '$code'");

//says thanks and your account is ready for use

echo "Thank you, Your account has been verified.";

}

}else

//if we have posted the register for we will register this user

if(isset($_GET['register'])) {

//check to see if any fields were left blank

if((!$_POST[username]) || (!$_POST[password]) || (!$_POST[cpassword]) || (!$_POST)) {

echo "A field was left blank please go back and try again.";

}else{

//posts all the data from the register form

$username = $_POST[username]; 

$password = $_POST[password]; 

$cpassword = $_POST[cpassword]; 

$email = $_POST;

//check see if the 2 passwords are the same

if($password == $cpassword)

{

//encrypts the password 8 times

$password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($password)))))))); 

$cname = mysql_query("SELECT `username` FROM `members` WHERE `username` = '$username'"); 

$cname= mysql_num_rows($cname); 

//checks to see if the username or email allready exist

if($cname>=1) { 

echo "The username is already in use"; 

}else{

//gets rid of bad stuff from there username and email

$username = addslashes(htmlspecialchars($username)); 

$email = addslashes(htmlspecialchars($email));

 

if($semail == "1") { // $email set as 1 means email activation is active

//adds them to the db

$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`) VALUES('$username','$password','$email')");

//posible letters for the verification code

$alphanum  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

//shuffles the letters around to create a 16 long code

$code = substr(str_shuffle($alphanum), 0, 16); 

//adds there code along with there user name to the db

$addcode = mysql_query("INSERT INTO `verification` (`username`, `code`) VALUES('$username','$code')");

//don't edit this, this is the link for there activication

$link = "

//sends the email to the person

mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename.

Please copy the below link into you address bar,

 

$link", "From: Site Verification");

//message sent now lets tell them to check there email

echo "You are now registered,<br><br>Please check your email to activate your account.";

}else{ //no need for email activation

$adduser = mysql_query("INSERT INTO `members` (`username`, `password`, `email`, `userlevel`) VALUES('$username','$password','$email','2')");

echo "You are now registered,<br><br>You can now loggin to your account";

}

}

}else{

echo "Your password and conformation password do not match!";

}

}

}else{

//none of the above so lets show the register form

echo "<form action='register.php?register' method='post'>

<table width='350'>

  <tr>

    <td width='150'>Username:</td>

    <td width='200'><input type='text' name='username' size='30' maxlength='25'></td>

  </tr>

  <tr>

    <td>Password:</td>

    <td><input type='password' name='password' size='30' maxlength='25'></td>

  </tr>

  <tr>

    <td>Confirm Password:</td>

    <td><input type='password' name='cpassword' size='30' maxlength='25'></td>

  </tr>

  <tr>

    <td>Email:</td>

    <td><input type='text' name='email' size='30' maxlength='55'></td>

  </tr>

  <tr>

    <td colspan='2'><center><input type='submit' value='Register'></center></td>

  </tr>

</table>

</form>";

}

echo "<center>";

?>

 

Now people can register lets let them login

 

login.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

 

if($logged[id]) {

//welcomes the member

echo "Welcome $logged[username]<br><br>";

//shows the user menu

echo "

- <a href='editprofile.php'>Edit Profile</a><br>

- <a href='changepassword.php'>Change Password</a><br>

- <a href='members.php'>Members</a><br>

- <a href='logout.php?logout'>Logout</a>";

}else

//if there trying to login

if(isset($_GET['login'])) {

//removes sql injections from the data

$username= htmlspecialchars(addslashes($_POST[username])); 

//encrypts the password

$password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST[password]))))))));

//gets the username data from the members database

$uinfo = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); 

//see if the user exists

$checkuser = mysql_num_rows($uinfo);

//if user name not found in database error

if($checkuser == '0')

{

echo "Username not found";

}else{

//fetch the sql

$udata = mysql_fetch_array($uinfo);

//checks see if the account is verified

if($udata[userlevel] == 1) { 

echo "This account had not been verified.";

}

//if it is continue

else

//if the db password and the logged in password are the same login

if($udata[password] == $password) {

$query = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); 

//fetchs the sql

$user = mysql_fetch_array($query);

//sets the logged session

$_SESSION['id'] = "$user[id]";

$_SESSION['password'] = "$user[password]";

 

echo "You are now logged in, Please wait. . .";

//redirects them

echo "<meta http-equiv='Refresh' content='2; URL=login.php'/>";

}

//wrong password

else{

echo "Incorrect username or password!"; 

}

}

}else{

//If not the above show the login form

echo "<form action='login.php?login' method='post'>

<table width='312'>

  <tr>

    <td width='120'>Username:</td>

    <td width='180'><input type='text' name='username' size='30' maxlength='25'></td>

  </tr>

  <tr>

    <td>Password:</td>

    <td><input type='password' name='password' size='30' maxlength='25'></td>

  </tr>

    <tr>

    <td colspan='2'><center><input type='submit' value='Login'></center></td>

  </tr>

</table>

 

</form>";

}

echo "<center>";

?>

 

Now lets make the logout page

 

logout.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

//checks there trying to logout

if(isset($_GET['logout'])) {

//deletes the sessions

unset($_SESSION['id']);

unset($_SESSION['password']);

//loggedout message

echo "You are now logged out.";

}

echo "<center>";

?>

 

Now lets display all the members

 

members.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

if(isset($_GET['user'])) { //if there trying to view a profile

//gets the user name and makes it safe

$username = addslashes($_GET[user]);

//querys the db to find the username

$getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");

//checks see if the username exists in the db 

 

$usernum = mysql_num_rows($getuser);

//if it don't exist 

if($usernum == 0) 

 

//don't exist

 

echo ("User Not Found"); 

 

//if it does exist then show there profile

else{

$user = mysql_fetch_array($getuser); 

echo "

<b>$user[username]'s Profile</b><br><br>

Email: $user<br>

Location: $user[location]<br>

Sex: $user[sex]<br>

Age: $user[age]

";

 

}

}else{

//gets all the members from the database

$getusers = mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error()); 

//loops there name out

while ($user = mysql_fetch_array($getusers)) { 

echo "<a href='members.php?user=$user[username]'>$user[username]</a><br>"; 

}

}

echo "<center>";

?>

 

Now we will make them able to edit there profile

 

editprofile.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

//checks see if there logged in

if($logged[id]) { 

if(isset($_GET['update'])) {

$email = addslashes(htmlspecialchars($_POST)); 

$location = addslashes(htmlspecialchars($_POST[location])); 

$age = (int)addslashes(htmlspecialchars($_POST[age])); 

$sex = addslashes(htmlspecialchars($_POST[sex])); 

//checks the sex if its ok

if(($sex == "Male") || ($sex == "Female")) {

//updates there profile in the db

$update = mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex', `age` = '$age', `location` = '$location' WHERE `username` = '$logged[username]'");

echo "Profile updated!";

}

//if the sex is invalid

else{

echo "Invalid sex input!";

}

}else{

$getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");

$user = mysql_fetch_array($getuser); 

echo "<form action='editprofile.php?update' method='post'>

Email: <input type='text' name='email' size='30' maxlength='55' value='$user'><br>

Location: <input type='text' name='location' size='30' maxlength='40' value='$user[location]'><br>

Age: <input type='text' name='age' size='3' maxlength='3' value='$user[age]'><br>

Sex: <select size='1' name='sex' value='$user[sex]'>

<option value='Male' "; if($user[sex] == Male) { 

echo "selected"; } 

echo ">Male</option> 

<option value='Female' "; if($user[sex] == Female) { 

echo "selected"; } 

echo ">Female</option>

</select><br>

<input type='submit' value='Update'>

</form>";

}

}else{

echo "You are not logged in.";

}

echo "<center>";

?>

 

Last thing is to let them change there password

 

changepassword.php

 

<?php

session_start(); //allows session

include "config.php";

echo "<center>";

//checks see if there logged in

if($logged[id]) { 

if(isset($_GET['update'])) {

//posts the passwords

$oldpassword = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST[oldpassword])))))))); 

$newpassword = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST[newpassword]))))))));

$cnewpassword = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST[cnewpassword]))))))));

//get the users old info from the database

$info = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'"); 

 

$info = mysql_fetch_array($info);

//if the old password matches the password in the database we continue

 

if($info[password] == $oldpassword) {

//if the new password and conformation password are the same continue

if($newpassword == $cnewpassword) {

$update = mysql_query("UPDATE `members` SET `password` = '$newpassword' WHERE `username` = '$logged[username]'");

echo "Password Updated, You will need to relogin with your new password.";

unset($_SESSION['id']);

unset($_SESSION['password']);

}else{

echo "Your new password and conformation password do not match!";

}

}else{

echo "Your old password does not match the database password!";

}

}else{

//shows the form if not already updated

echo "<form action='changepassword.php?update' method='post'>

 

Old Password: <input type='password' name='oldpassword' size='30' maxlength='50'><br>

New Password: <input type='password' name='newpassword' size='30' maxlength='50'><br>

Confirm Password: <input type='password' name='cnewpassword' size='30' maxlength='50'><br>

<input type='submit' value='Change'>

</form>";

}

}else{

echo "You are not logged in.";

}

echo "<center>";

?>

 

which is the problem

Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in C:\AppServ\www\local_hany\register.php on line 72

You are now registered,

 

Please check your email to activate your account.

 

can you help my

 

It probably doesn't like your FROM header you are sending to mail. Try replacing this:

mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename.
Please copy the below link into you address bar,

$link", "From: Site Verification");

with

mail("$email", "Member-Ship Validation", "Thank you for registering on $sitename.
Please copy the below link into you address bar,

$link", "From: Site Verification <[email protected]>");

where [email protected] is some general email address at your domain.

I have other problem

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\AppServ\www\local_hany\register.php on line 72

 

C:/windows/php.ini

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

; For Win32 only.

;sendmail_from = ******@hotmail.com

 

can you help my

 

 

I have other problem

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\AppServ\www\local_hany\register.php on line 72

 

C:/windows/php.ini

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

; For Win32 only.

;sendmail_from = ******@hotmail.com

 

can you help my

 

 

 

a semi-colon in front of a line in php.ini comments it out. remove the ; from the front of that line

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.