Forum Moderators: coopster
Code:
<?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);
$filename = 'tmprmv.txt';
$pipe = "¦";
$cr = "\n";
$data .= $email_address . $pipe . $email_id . $cr;
$confirm_message = " http://example.co.nz/newsletterunsubscribe.php?email=$email&action=add&id=$email_id";
if($_POST["action"] == "send") {
$fp = fopen("subscribers.txt", "r");
$file_text = fread($fp, 999999);
fclose($fp);
$subscribers = explode(",",$file_text);
foreach($subscribers as $subscriber) {
if($subscriber!= $email) {// Should that be $_POST["email"]?
die("<div id=\"content\"><h3><b>Sorry</b> we cannot find your email on the list</h3></div>");
} else {
$fp = fopen($filename,"a");
if($fp) {
fwrite($fp,$data); // Write information to the file
fclose($fp); // Close the file
}
}
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;
charset=iso-8859-1' . "\r\n";
$headers .= 'From: email' . "\r\n";
mail($_POST["email"], Confirmation, $confirm_message, $headers);
$msg = "A confirmation email has been sent out to you";
}
?>
<!-- content -->
<div id="content">
<h3> <?php echo "$msg"; ?>
<?php if($_POST["action"] != "send") { ?>
<form name=add action='test_unsubscribe.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>
<?php }?>
</h3>
</div>
<!-- // content --> <?php include ("inc/files/footer.php"); ?>
[edited by: coopster at 4:26 pm (utc) on Jan. 9, 2006]
[edit reason] formatted code [/edit]
//$_POST["email"] = $email;
// Should it be this instead?
$email = $_POST["email"];