[ Just a note that this script originally comes from OpenNewsletter-1.1 ]
Hi
I have been trying to set up a script where the user types in their email address in a form and when they click submit it adds their email address and a random number to a temporary file and sends them out a confirmation email with the random number under "id".
When they click on the link it takes them to the confirmation page where it checks the id from the email with the one in the temporary file, if there is a match it submits.
At the moment it saves properly but I can't get it to check properly.
Cheers.
"email.php"
<?php $page="about"; include ("inc/files/header.php");
$_POST["email"] = $email;
$number = rand(1000, 9999);
$email_address = stripslashes($_POST['email']);
$email_id = "$number";
$email_id = md5($email_id);
// tried using crypt but I wondered
// about URLs...
$filename = 'tmp.txt';
$pipe = "|";
$cr = "\n";
$data .= $email_address . $pipe . $email_id . $cr;
$confirm_message = "
\"http://website.com/newslettersubscribe.php?email=$email&action=add&id=$email_id \"";
if($_POST["action"] == "send")
{
$fp = fopen($filename,"a");
if($fp){
fwrite($fp,$data); // Write information to the file
fclose($fp); // Close the file
}
mail($_POST["email"], Confirmation, $confirm_message, "From: test");
$msg = "A confirmation email has been sent out to you";
}
?>
<!-- content -->
<div id="content">
<h3>
<?php echo "$msg"; ?>
<form name=add action='test.php' method='POST'>
Email: <input class=textField type=text name=email>
<input class=button type=submit value=Send>
<input type=hidden name=action value=send>
</form>
<script language=javascript>
var validator = new Validator('add');
validator.addValidation('email','req','Please enter a valid email');
validator.addValidation('email','email','Please enter a valid email');
</script>
</h3>
</div>
<!-- // content -->
<?php include ("inc/files/footer.php"); ?>
"suscribe.php"
<?php
$new_email_address = $_GET['email'];
$new_email_id = $_GET['id'];
// Get list of valid users
$file = file('tmp.txt');
// Process list of existing users into name/pwd arrays
foreach ($file as $line) {
$user[] = explode("|",$line);
$user_name[] = trim($user[0]);
$user_pwd[] = trim($user[1]);
}
$found = false;
foreach($user_name as $key => $user) {
if($user_name[$key] == $new_email_address) {
$pwd = md5($new_email_id, $user_pwd[$key]);
if($user_pwd[$key] == $pwd) {
$found = true;
break 3;
}
}
}
// Do user specific action
if($found) {
$fp = fopen("subscribers.txt", "r");
$file_text = fread($fp, 999999);
fclose($fp);
$subscribers = explode(",",$file_text);
foreach($subscribers as $subscriber)
{
if($subscriber == $_GET["email"])
{
$result = 1;
break;
}
else
{
$result = 0;
}
}
if($result == 1)
{
$msg = "<h3>Sorry, we cannot add you as... you already exist on this list...</h3>";
}
else
{
$fp = fopen("subscribers.txt", "a+");
fwrite($fp, $_GET["email"] . ",");
fclose($fp);
$msg = "<h3>You have been added to the newsletter. Thanks!</h3>";
}
}
else {
die ('no');
}
$page="about"; include ("inc/files/header.php"); ?>
<!-- content -->
<div id="content"><?php echo "$msg"; ?></div>
<!-- // content -->
<?php include ("inc/files/footer.php"); ?>
Any ideas?
Thanks