Sending an email confirmation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
craig2009
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 5:34 pm

Sending an email confirmation

Post by craig2009 »

The following code returns 'Cannot send Confirmation link to your e-mail address', when testing with data, can someone please tell me why? many thanks in advance

Code: Select all

<?
include('config.php');
 
// table name
$tbl_name=temp_members_db;
 
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
 
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
 
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);
 
// if suceesfully inserted data into database, send confirmation link to email
if($result){
 
// ---------------- SEND MAIL FORM ----------------
 
// send e-mail to ...
$to=$email;
 
// Your subject
$subject="Your confirmation link here";
 
// From
$header="from: your name <your email>";
 
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
 
// send email
$sentmail = mail($to,$subject,$message,$header);
 
}
 
// if not found
else {
echo "Not found your email in our database";
}
 
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
 
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Sending an email confirmation

Post by jackpf »

Have you got an smtp server installed on your server?
craig2009
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 5:34 pm

Re: Sending an email confirmation

Post by craig2009 »

Thank you, I thought it might be something along those lines, I was using a test server on my pc but have since uploaded to a web based hosting server and all works as planned.

Thank you for the advice it saved me loads of time and effort. Cheers jackpf
craig2009
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 5:34 pm

Re: Sending an email confirmation

Post by craig2009 »

Thanks for above info..some more help required... Password for the user that is registering takes the value of the database/or forum login of my web host. It isn't taking the users inputted password.

Code: Select all

<?
include('config.php');
 
// Passkey that got from link
$passkey=$_GET['passkey'];
 
$tbl_name1="temp_members_db";
 
// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);
 
// If successfully queried
if($result1){
 
// Count how many row has this passkey
$count=mysql_num_rows($result1);
 
// if found this passkey in our database, retrieve data from table "temp_members_db"
if($count==1){
 
$rows=mysql_fetch_array($result1);
$name=$rows['name'];
$email=$rows['email'];
$password=$rows['password'];
$country=$rows['country'];
 
$tbl_name2="registered_members";
 
// Insert data that retrieves from "temp_members_db" into table "registered_members"
$sql2="INSERT INTO $tbl_name2(name, email, password, country)VALUES('$name', '$email', '$password', '$country')";
$result2=mysql_query($sql2);
}
 
// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
}
 
// if successfully moved data from table"temp_members_db" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"
if($result2){
 
echo "Your account has been activated";
 
// Delete information of this user from table "temp_members_db" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);
 
}
 
}
?>

Code: Select all

<?
include('config.php');
 
// Passkey that got from link
$passkey=$_GET['passkey'];
 
$tbl_name1="temp_members_db";
 
// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);
 
// If successfully queried
if($result1){
 
// Count how many row has this passkey
$count=mysql_num_rows($result1);
 
// if found this passkey in our database, retrieve data from table "temp_members_db"
if($count==1){
 
$rows=mysql_fetch_array($result1);
$name=$rows['name'];
$email=$rows['email'];
$password=$rows['password'];
$country=$rows['country'];
 
$tbl_name2="registered_members";
 
// Insert data that retrieves from "temp_members_db" into table "registered_members"
$sql2="INSERT INTO $tbl_name2(name, email, password, country)VALUES('$name', '$email', '$password', '$country')";
$result2=mysql_query($sql2);
}
 
// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
}
 
// if successfully moved data from table"temp_members_db" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"
if($result2){
 
echo "Your account has been activated";
 
// Delete information of this user from table "temp_members_db" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);
 
}
 
}
?>

Code: Select all

<?
include('config.php');
 
// Passkey that got from link
$passkey=$_GET['passkey'];
 
$tbl_name1="temp_members_db";
 
// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);
 
// If successfully queried
if($result1){
 
// Count how many row has this passkey
$count=mysql_num_rows($result1);
 
// if found this passkey in our database, retrieve data from table "temp_members_db"
if($count==1){
 
$rows=mysql_fetch_array($result1);
$name=$rows['name'];
$email=$rows['email'];
$password=$rows['password'];
$country=$rows['country'];
 
$tbl_name2="registered_members";
 
// Insert data that retrieves from "temp_members_db" into table "registered_members"
$sql2="INSERT INTO $tbl_name2(name, email, password, country)VALUES('$name', '$email', '$password', '$country')";
$result2=mysql_query($sql2);
}
 
// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
}
 
// if successfully moved data from table"temp_members_db" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"
if($result2){
 
echo "Your account has been activated";
 
// Delete information of this user from table "temp_members_db" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);
 
}
 
}
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Sending an email confirmation

Post by jackpf »

Right...so what's it saying? Or is it just blank?
swisse
Forum Newbie
Posts: 1
Joined: Fri Jul 10, 2009 6:32 pm

$_POST instead of $_GET

Post by swisse »

instead of:
$passkey=$_GET['passkey'];

try:
$passkey=$_POST['passkey'];

if you used method="post" in your form
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Sending an email confirmation

Post by jackpf »

Or $_REQUEST if you don't know.
Post Reply