Page 1 of 1

Sending an email confirmation

Posted: Thu Jul 09, 2009 5:38 pm
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";
}
 
?>

Re: Sending an email confirmation

Posted: Thu Jul 09, 2009 5:43 pm
by jackpf
Have you got an smtp server installed on your server?

Re: Sending an email confirmation

Posted: Thu Jul 09, 2009 7:30 pm
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

Re: Sending an email confirmation

Posted: Thu Jul 09, 2009 8:28 pm
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);
 
}
 
}
?>

Re: Sending an email confirmation

Posted: Thu Jul 09, 2009 9:56 pm
by jackpf
Right...so what's it saying? Or is it just blank?

$_POST instead of $_GET

Posted: Fri Jul 10, 2009 6:36 pm
by swisse
instead of:
$passkey=$_GET['passkey'];

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

if you used method="post" in your form

Re: Sending an email confirmation

Posted: Fri Jul 10, 2009 6:59 pm
by jackpf
Or $_REQUEST if you don't know.