Hello everybody,
I've a contact form and when the user submits the form, i save all the information into a table and I send an e-mail to the user who filled in.
What does this e-mail do???
I just send a link in-order to activate his e-mail address.Once the user click on the link and activates his e-mail,I would like to show a message, your e-mail has been activated.If the e-mail is activated, I update the table and set the column activated=1.
The following code seems to be working fine except the print message-"the e-mail has been activated."
Well, I dont check in this script if the e-mail entered in in a proper format, i already did that check using java-script in my contactform.
Could somebody tell me where the error is or if there is any un-necessary code.
Thanks
<?php
/*This script will handle the variables passed from the contact form*/
//Declare the relevant variables
$hostname = "";
$username = "";
$password = "";
$dbname = "";
$mytable = "user_information";
$adminaddress = "";
//Database connection
mysql_connect($hostname,$username,$password)or die ("unable to connect my database");
mysql_select_db("$dbname") or die ("unable to select database");
echo "<body bgcolor='#FFFFCC'>";
echo "<CENTER>";
echo "Hello, $name";
echo "<BR><BR>";
echo "Thank you for your interest.<BR><BR>";
echo "We have sent you an activation e-mail to $email.Please check your e-mail";
echo "<CENTER>";
$from = $_REQUEST['email'];
// create the MD5 hash
$secret_code = 'secret';
$formatted_email = preg_replace("/(-|\@|\.)/", "", $from);
$hashed = md5("$secret_code $formatted_email");
// wait, are we verifying the email?
if($_REQUEST['m'] != "") {
// this is validation routine
if($hashed == $_REQUEST['m']) {
print("Congrats, you have successfully validated your email address.");
// add the email to your double opt-in list here
exit;
} else {
print("Sorry, this email does not validate");
}
} else {
// since we aren't validating then it is time to send out validation mail
$mail_body = "To validate this email click the following link:\nhttp://www.blahblah.com/project/activate.php?email=$from&m=$hashed";
mail($from, "Validation Email", $mail_body, "From: Admin\n");
print("Please check your email <b>$from</b> for the test validation message");
}
//Send the relevant email
mail ("ich@inkaytown.f2o.org", "visitor request for info", "$name requested for information.The email address is $email");
//Insert into the table
$query = "insert into $mytable (name, email, text, contacted_id) values ('$name','$email','$description','$id')";
$result = mysql_query($query);
//We close the MySQL connection
mysql_close();
?>
activate.php
$sql = mysql_query("UPDATE $mytable SET activated='1' WHERE activated='$hashed'");
?>