Jump to content

[SOLVED] emailing users when signing up


runnerjp

Recommended Posts

hey guys,,, i got a members are set up and im haveing a problem wiht the fact that people are registering without proper emails e.e [email protected].... is there a way where for a user to sign up they have to have a random password sent to their email address... that way i can tell that their email is real or have them activate thair account via email ?

 

if any 1 could help me out i would be very gratefull :D

 

 

this is what i have set up so far

 

 

<?php
if($_SERVER[php_SELF]=="/include/do_reg.inc.php")
{
    header("Location: /index.php");
    exit;
}

//check input for errors
$login_length = strlen($_POST['login']);
$pass_length = strlen($_POST['pass1']);
$login = $_POST['login'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];
$displayname = $_POST['displayname'];
$agreestoterms = $_POST['agreestoterms'];

if(empty($login)) {
echo "You did not enter a Username! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($pass1)) {
echo "You did not enter a password! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($pass2)) {
echo "You did not verify your password! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if("$pass1" != "$pass2") {
echo "Your passwords do not match! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($email)) {
echo "You did not enter your email! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($displayname)) {
echo "You did not enter your Display Name! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($agreestoterms)) {
echo "You must agree to terms of service to register! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if($login_length < 3) {
echo "Your Username must be at least 3 characters long. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if($pass_length < 3) {
echo "Your password must be at least 3 characters long. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$", $email)) {
$okmail="1";
}
if($okmail != "1") {
echo "Your email address is not properly formatted! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$login)) {
$oklogin="1";
}
if($oklogin != "1") {
echo "Your Username can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$pass1)) {
$okpass="1";
}
if($okpass != "1") {
echo "Your password can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$displayname)) {
$okdisplay="1";
}
if($okdisplay != "1") {
echo "Your Display Name can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$checkl = "SELECT * FROM $tbl_members WHERE login = \"$login\"";
$check_l = @mysql_query($checkl,$connection) or die("Couldn't execute login check query.");
while ($row = mysql_fetch_array($check_l)) {
$ch_login = $row['login'];
}
if(isset($ch_login)) {
echo "The Username <b>$ch_login</b> is taken. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}

$check2 = "SELECT * FROM $tbl_restricted WHERE r_login = \"$login\"";
$check_2 = @mysql_query($check2,$connection) or die("Couldn't execute login check query.");
while ($row = mysql_fetch_array($check_2)) {
$r_login = $row['r_login'];
}
if(isset($r_login)) {
echo "The Username <b>$r_login</b> is reserved. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}



$checke = "SELECT * FROM $tbl_members WHERE email = \"$email\"";
$check_e = @mysql_query($checke,$connection) or die("Couldn't execute email check query.");
while ($row = mysql_fetch_array($check_e)) {
$ch_email = $row['email'];
}
if(isset($ch_email)) {
echo "There is already an account with that email address.<br><br><a href=\"forgot.php\">Retrieve Login information.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($newsletter)) $newsletter = "no";
//input is ok, register new member!

$ipaddr = $_SERVER['REMOTE_ADDR'];

$sql = "INSERT INTO $tbl_members (login, enabled, password, email, displayname, newsletter, ipaddr)
VALUES (\"$login\", \"$autoenable\", \"$pass1\", \"$email\", \"$displayname\", \"$newsletter\", \"$ipaddr\")";
$result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

if($mailonnew == "yes") {
$to = "$site_email";
$subject = "New $sitename Member!";
$from_mail = "$adminemail";
$message = "Dear Admin,\n\n";
$message .= "You have a new member with the login: $login.\n\n";
$message .= "$siteurl";
$headers = "From: $from_mail\r\n";
$headers .= "Reply-To: $from_mail\r\n";
$headers .= "X-Mailer: phpProfiles";
mail($to, $subject, $message, $headers);
}
include("include/welcome_msg.inc.php");
include("include/reg_success.inc.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/47227-solved-emailing-users-when-signing-up/
Share on other sites

I cud give u an idea

 

after the user registers ,send a mail to the given email id including a link with the parameters,username,password and a status with value yes

if the email addr is valid ,when the user clicks on the link ,the variables are recieved in a page and the status is set to true in the database.

if the emailaddr is invalid the staus remains false and hence the user wud not be registerd.

ok if this helps i allready have an enabled area set up

<select name="ed_enabled" size="1">
            <?
		$enable_a=array("yes","no");
		while (list($key, $val) = each($enable_a)) {
		if ($ed_enabled  == $val) {$selected="selected";} else {$selected="";}
		echo "<option value=\"$val\" $selected>".ucwords(strtolower($val))."</option>\n";
		}
		?>

 

this means i can manually change it but i dont want it to be manual changed because it takes alot of time lol

 

 

is it any help?

hmm

i guess i had smethn else in mind

heres how it goes

 

when the user clicks on register-a mail is shot with the parameters obtained from the post

the mail wud have a link in the body. for eg:

 <a href="validate.php?username=''&pwd=''&status='true'>click here to confirm</a>

.

 

the validate .php wud  get the values thru GET and change the status of the user to valid

[assuming that u wud have the table with fileds user,pwd and status].

u wud get the username and pwd with the link itself.

so all u need is a validate.php page and a link sent to the email

no manual work needs to be done

In the validate page

you wud get the values from the link

 

$username=$_GET["username"];

$status=$_GET["status"];

 

write a query to update the table and change the status to true where the username is $username

 

so when the user registers the username ,pwd and staus wud be inserted in the database- the staus wud be false initially

 

 

ok that all makes sence but what i dont get is if i put <a href="validate.php?username='$login'&pwd='$pass1'&status='true'>click here to confirm</a>

 

how it would find the users password and username to register them??

 

does it match up with there email or some thing

 

 

sorry about all this just wanna get grasp of it :)

ok this is wat happens:

 

when they click on register  the values the user eneterd wud be posted to another page rite?

 

lets say on clickin register the form is submitted to get_values.php.

here u use the POST to get the values

$username=$_POST[]

$pwd=$_POST[]

$email=$_POST[]

 

on the same page u wud have the mail sent to the user.so  you can attatch the parameters to the link here

$body="<a href='validate.php?user=$username&pwd=$pwd&status=true>Please click to confirm</a>

 

this way we wud get the username and pwd in the validate.php page when the user clicks to confirm

ok would it look something like this??

[code]$ipaddr = $_SERVER['REMOTE_ADDR'];

$sql = "INSERT INTO $tbl_members (login, enabled, password, email, displayname, newsletter, ipaddr)
VALUES (\"$login\", \"$autoenable\", \"$pass1\", \"$email\", \"$displayname\", \"$newsletter\", \"$ipaddr\")";
$result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

if($mailonnew == "yes") {
$to = "$site_email";
$subject = "New $sitename Member!";
$from_mail = "$adminemail";
$message = "Dear Admin,\n\n";
$message .= "You have a new member with the login: $login.\n\n";
$message .= "$siteurl";
$headers = "From: $from_mail\r\n";
$headers .= "Reply-To: $from_mail\r\n";
$headers .= "X-Mailer: phpProfiles";
mail($to, $subject, $message, $headers);
}
$to = "$email";
$subject = "New $sitename Member!";
$from_mail = "$adminemail";
$message = "Dear $displayname";
$message .= "<a href='http://www.runnerselite.com/reg_success.inc.php?user=$username&pwd=$pwd&status=true>Please click to confirm[/url]"
";
$message .= "$siteurl";
$headers = "From: $from_mail\r\n";
mail($to, $subject, $message, $headers);
}
include("include/welcome_msg.inc.php");
include("include/reg_success.inc.php");
?>

 

 

then reg_success being

 

[coe]

<table align="center" cellpadding="4" cellspacing="0" width="80%">

    <tr>

        <td width="973">

            <p align="center">Registration was successful. Thanks for joining us!</p>

            <p align="center">Please log in to create your profile. Once you are logged in, use the My Profile link

            to create your new profile.</p>

          </td>

    </tr>

</table>

<form action="login.php" method="POST">

<table align="center" cellpadding="4" cellspacing="0" class="login_tbl">

    <tr>

        <td class="login_cell">

            <p>Username</p>

        </td>

        <td class="login_cell">

            <p><input type="text" name="login" maxlength="20" size="10" style="font-family:Arial,sans-serif; font-size:9pt;"></p>

        </td>

    </tr>

    <tr>

        <td class="login_cell">

            <p>Password</p>

        </td>

        <td class="login_cell">

            <p><input type="password" name="password" maxlength="20" size="10" style="font-family:Arial,sans-serif; font-size:9pt;"></p>

        </td>

    </tr>

    <tr>

        <td class="login_cell">

            <p> </p>

        </td>

        <td class="login_cell">

            <p><input type="hidden" name="ref" value="<?echo $userurl ?>/newprofile.php">

            <input type="submit" value="Login!" style="font-family:Arial,sans-serif; font-size:9pt;"></p>

        </td>

    </tr>

</table>

</form>

<p align="center"> </p>[/code] ??

 

that right ?

maybe try to change

$message .= "<a href='http://www.runnerselite.com/reg_success.inc.php?user=$username&pwd=$pwd&status=true>Please click to confirm[/url]"

 

to

$message .= "<a href=\"http://www.runnerselite.com/reg_success.inc.php?user=$username&pwd=$pwd&status=true\">Please click to confirm[/url]"

 

and ofcourse again... [/url] = < /a> (without space)

nope i get error page...says failed to open "user=".$username."&pwd=".$pwd&status."=true\"

 

have i done something wrong :S

 

<?php
if($_SERVER[php_SELF]=="/include/do_reg.inc.php")
{
    header("Location: /index.php");
    exit;
}

//check input for errors
$login_length = strlen($_POST['login']);
$pass_length = strlen($_POST['pass1']);
$login = $_POST['login'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$email = $_POST['email'];
$displayname = $_POST['displayname'];
$agreestoterms = $_POST['agreestoterms'];

if(empty($login)) {
echo "You did not enter a Username! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($pass1)) {
echo "You did not enter a password! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($pass2)) {
echo "You did not verify your password! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if("$pass1" != "$pass2") {
echo "Your passwords do not match! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($email)) {
echo "You did not enter your email! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($displayname)) {
echo "You did not enter your Display Name! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($agreestoterms)) {
echo "You must agree to terms of service to register! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if($login_length < 3) {
echo "Your Username must be at least 3 characters long. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if($pass_length < 3) {
echo "Your password must be at least 3 characters long. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if(ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$", $email)) {
$okmail="1";
}
if($okmail != "1") {
echo "Your email address is not properly formatted! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$login)) {
$oklogin="1";
}
if($oklogin != "1") {
echo "Your Username can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$pass1)) {
$okpass="1";
}
if($okpass != "1") {
echo "Your password can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
if (ereg("^[a-zA-Z0-9]+$",$displayname)) {
$okdisplay="1";
}
if($okdisplay != "1") {
echo "Your Display Name can contain only letters and numbers! Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$checkl = "SELECT * FROM $tbl_members WHERE login = \"$login\"";
$check_l = @mysql_query($checkl,$connection) or die("Couldn't execute login check query.");
while ($row = mysql_fetch_array($check_l)) {
$ch_login = $row['login'];
}
if(isset($ch_login)) {
echo "The Username <b>$ch_login</b> is taken. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}

$check2 = "SELECT * FROM $tbl_restricted WHERE r_login = \"$login\"";
$check_2 = @mysql_query($check2,$connection) or die("Couldn't execute login check query.");
while ($row = mysql_fetch_array($check_2)) {
$r_login = $row['r_login'];
}
if(isset($r_login)) {
echo "The Username <b>$r_login</b> is reserved. Please <a href=\"javascript:history.go(-1);\">Try again.</a>";
include("include/footer.inc.php");
exit;
}



$checke = "SELECT * FROM $tbl_members WHERE email = \"$email\"";
$check_e = @mysql_query($checke,$connection) or die("Couldn't execute email check query.");
while ($row = mysql_fetch_array($check_e)) {
$ch_email = $row['email'];
}
if(isset($ch_email)) {
echo "There is already an account with that email address.<br><br><a href=\"forgot.php\">Retrieve Login information.</a>";
include("include/footer.inc.php");
exit;
}
if(empty($newsletter)) $newsletter = "no";
//input is ok, register new member!

$ipaddr = $_SERVER['REMOTE_ADDR'];

$sql = "INSERT INTO $tbl_members (login, enabled, password, email, displayname, newsletter, ipaddr)
VALUES (\"$login\", \"$autoenable\", \"$pass1\", \"$email\", \"$displayname\", \"$newsletter\", \"$ipaddr\")";
$result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

if($mailonnew == "yes") {
$to = "$site_email";
$subject = "New $sitename Member!";
$from_mail = "$adminemail";
$message = "Dear Admin,\n\n";
$message .= "You have a new member with the login: $login.\n\n";
$message .= "$siteurl";
$headers = "From: $from_mail\r\n";
$headers .= "Reply-To: $from_mail\r\n";
$headers .= "X-Mailer: phpProfiles";
mail($to, $subject, $message, $headers);
}
$to = "$email";
$subject = "New $sitename Member!";
$from_mail = "$adminemail";
$message = "Dear $displayname";
$message .= "<a href=\"http://www.runnerselite.com/reg_success.inc.php?user=".$username."&pwd=".$pwd&enabled."=yes\">Please click to confirm[/url]";
$message .= "$siteurl";
$headers = "From: $from_mail\r\n";
mail($to, $subject, $message, $headers);
include("include/welcome_msg.inc.php");
include("include/reg_success.inc.php");
?>

thats my page where it send an email ( that works)

 

then this is page they are sent to ( been re_success)

 

<table align="center" cellpadding="4" cellspacing="0" width="80%">
    <tr>
        <td width="973">
            <p align="center">Registration was successful. Thanks for joining us!</p>
            <p align="center">Please log in to create your profile. Once you are logged in, use the My Profile link
            to create your new profile.</p>
          </td>
    </tr>
</table>
<form action="login.php" method="POST">
<table align="center" cellpadding="4" cellspacing="0" class="login_tbl">
    <tr>
        <td class="login_cell">
            <p>Username</p>
        </td>
        <td class="login_cell">
            <p><input type="text" name="login" maxlength="20" size="10" style="font-family:Arial,sans-serif; font-size:9pt;"></p>
        </td>
    </tr>
    <tr>
        <td class="login_cell">
            <p>Password</p>
        </td>
        <td class="login_cell">
            <p><input type="password" name="password" maxlength="20" size="10" style="font-family:Arial,sans-serif; font-size:9pt;"></p>
        </td>
    </tr>
    <tr>
        <td class="login_cell">
            <p> </p>
        </td>
        <td class="login_cell">
            <p><input type="hidden" name="ref" value="<?echo $userurl ?>/newprofile.php">
            <input type="submit" value="Login!" style="font-family:Arial,sans-serif; font-size:9pt;"></p>
        </td>
    </tr>
</table>
</form>
<p align="center"> </p>

 

( ow and thanks for lookin into this again suzzane... very glad you are here to help :D)

k in te second page

u need to get the parameters using GET

if(isset($_GET["username"]))

{

$username=$)GET[];

$pwd=$_GET[];

$status=$_GET[];

 

$res=mysql_query(update tblname set status='true' where username='$username')

}

 

n thts it

after this you can give any message to the user such as "Thank You for reg...etc etc

 

ok i have done this for regsuccess --

<?php if(isset($_GET["username"]))
{
$username=$)GET[];
$pwd=$_GET[];
$enabled=$_GET[];

$res=mysql_query(update tblname set enabled='yes' where username='$username')
}
?>

but this

http://www.runnerselite.com/reg_success.inc.php?user=".$username."&pwd=".$pwd&enabled."=yes\"

does not show up as a link on my email ??

 

 

 

Fatal error: Cannot use [] for reading in /home/runnerse/public_html/include/reg_success.inc.php on line 3

 

this is what i get now lol so we r gttin sum where :P

 

<?php if(isset($_GET["username"]))
{
$username=$_GET[];
$pwd=$_GET[];
$enabled=$_GET[];

$res=mysql_query(update tblname set enabled='yes' where username='$username')
}
?>

btw do i need to add a connect msql on this bit cos this code is all i have on reg success!

<?php if(isset($_GET["username"]))
{
$username=$_GET[];
$pwd=$_GET[];
$enabled=$_GET[];

$res=mysql_query(update tblname set enabled='yes' where username='$username')
}
?>

 

hey u need to have the parameter names in the brackets.

ie if u have passed the username in the link this way

&user=$username

 

it shud be

$user=$_GET["user"];

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.