<?php

echo <<<EOD
<h1>Newsletter</h1>
Subscribe to our newsletter to receive information on {$mainkeyword}
EOD;

if(!isset($_POST['go'])) {
show_subform();
} else {
	//begin error checking
	if(trim($_POST['sendName']) == "") {
		$error[] = "You did not enter your  first name.";
	}

	$_POST['sendEmail'] = trim($_POST['sendEmail']);

	if(!isitvalid($_POST['sendEmail'])) {
		$error[] = "Your email address appears to be invalid.";
		unset($_POST['sendEmail']);
	}

	if($error) {
		echo "<center>\n";
		foreach($error as $oneError) {
			echo "$oneError<br>\n";
		}
		echo "</center>\n";

		echo show_subform();

} else { //no error

$subject="Internet Subscriber from :".$rooturl; //this is to identify the origin of the lead
$message="Customer FirstName:".$_POST['sendName']."\nCustomer Email:".$_POST['sendEmail'];
$headers = "From: ".$_POST['sendName']."<".$_POST['sendEmail'].">\r\n";
		$headers .= "X-Mailer: Subscription form \r\n";
		$headers .= "Content-Type: text/plain";
@mail($autoresponder, $subject, $message, $headers);
echo <<<EOD
<h2><font color="#FF0000">{$_POST['sendName']}, Welcome</h2></font><p>You will soon receive info on {$mainkeyword} to this email address : {$_POST['sendEmail']}</p>

EOD;
// You can edit the text above between the "EOD" tag (do not alter them and do not remove the newline) to fit your needs
}
}

/*void*/ function show_subform()
{

$sendName=(!isset($_GET['sn'])?$_POST['sendName']:urldecode($_GET['sn']));
$sendEmail=(!isset($_GET['se'])?$_POST['sendEmail']:urldecode($_GET['se']));
//just assign the sender vars either their get value(if set) otherwise the post val, even if blank

echo <<<EOD


<form method="post" action="{$_SERVER['PHP_SELF']}">
<input type="hidden" name="go" value="submit">
<table>
<tr><td colspan=2><center></center></td></tr>
<tr><td>Email:</td><td><input type="text" name="sendEmail" value="$sendEmail" size="10"></td></tr>
<tr><td>First Name:</td><td><input type="text" name="sendName" value="$sendName" size="10"></td></tr>
<tr><td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>
<hr>
EOD;
}


/* bool */ function isitvalid($email)
{
	return eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $email);
}


?>
