How could this be done?
$message=" You have successfully submitted the following information: Name: $name Email: $email ";
$message=" You have successfully submitted the following information: Name: $name Email: $email ";
|
|
|
<?
/*
Email list script
by phptutorial.info
*/
// to avoid showning errors (change to 1 to show them). For security
error_reporting(0);
// if info is posted, show the form and die
// the form is in the bottom of the page
if (!$_POST){print_form();die();}
// when info is posted you will be here
?>
<html>
<head>
<title></title>
</head>
<?
// SITE NAME
$site="yoursite.com";
//TITLE OF THE MAILINGLIST
$list_title="Title of the mailing list";
//SITE ADMIN NAME
$site_admin="name of site admin";
//Site admin e-mail
$site_admin_email="admin@yoursite.com";
//Message that will be sent to the user
$message="
Hi and welcome to the {$list_title}!
You have successfully subscribed with the following information:
Name: {$name}
Email: {$email}
test test test
test test test
test test test
http://downloadlink.com
If for any reason you do not want to receive any more emails from us, you can unsubscribe by removing your email address with this link: http://www.{$site}/email-list-script/emaillistscript.php
";
//Message headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$site_admin." ".$site."<".$site_admin_email.">\r\n";
// GET EMAIL
$email=$_POST["email"];
$name=$_POST["name"];
// To avoid problems, only lower case is used
$email=strtolower($email);
// Check whether email is correct by using a function
// function requires the email address and the error message
check_email ($email, "Email is not valid.");
// GET VALUE FOR action : subc (subscribe) or unsubc (unsubscribe)
$action=$_POST["action"];
// this is the file with the info (emails)
// When using the link in the top to download the complete script, a new name for this file
// will be generated (p.e.: emaillist-2ax1fd34rfs.txt), so users will be unable to find it
$file = "emaillist-subscribers.txt";
// lets try to get the content of the file
if (file_exists($file)){
// If the file is already in the server, its content is pasted to variable $file_content
$file_content=file_get_contents($file);
}else{
// If the file does not exists, lets try to create it
// In case file can not be created (probably due to problems with directory permissions),
// the users is informed (the first user will be the webmaster, who must solve the problem).
$cf = fopen($file, "w") or die("Error: file does not exits, and it cannot be created.<BR>Please check permissions in the directory or create a file with coresponding name.");
fclose($cf);
}
// IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE
if ($action=="subc"){
// check whether the email is already registered
if(strpos($file_content,"<$email>")>0){die("Your email is already included in this mailing list.");}
// write the email to the list (append it to the file)
$cf = fopen($file, "a");
fputs($cf, "\n$name <$email>"); // new email is written to the file in a new line
fclose($cf);
// notify subscription
print "Your information has been added. You will receive<br>an email with your subscription information shortly.";
mail($email,"$list_title",$message, "From: $site_admin_email");
}
// IF REQUEST HAS BEEN TO UNSUBSCRIBE FROM MAILING LIST, REMOVE EMAIL FROM THE FILE
if ($action=="unsubc"){
// if email is not in the list, display error
if(strpos($file_content,"<$email>")==0){die("Error: your email is not included in this mailing list.");}
// remove email from the content of the file
$file_content=preg_replace ("/\n <$email>/","",$file_content);
// print the new content to the file
$cf = fopen($file, "w");
fputs($cf, $file_content);
fclose($cf);
//code to fix unsubscribe error
function updateFile($fileName,$userName,$userEmail) {
$fp = '';
$myContent = '';
$fileContent = '';
$fp = fopen($fileName,'r');
if ($fp) {
while (!feof($fp)) {
$myContent = fgets($fp);
if ((preg_match("/$userEmail/",$myContent) == 1) && (preg_match("/$userName/",$myContent) == 1)) {
$myContent = '';
$fileContent = $fileContent.$myContent;
}
else {
$fileContent = $fileContent.$myContent;
}
}
fclose($fp);
$fp = fopen($fileName,'w');
if ($fp) {
fwrite($fp,$fileContent);
fclose($fp);
}
}
else {
die("\n Unable to open file.");
}
}
// notify unsubscription
print "Your email has been removed from our mailing list.";
}
?>
</body>
</html>
<?
// THIS FUNCTION WILL CHECK WHETHER AN EMAIL IS CORRECT OR NOT
// FIRST, BASIC ARCHITECTURE IS CHECKED
// THEM, EXISTANCE OF THE EMAIL SERVER IS CHECKED
// If email is not correct, the error message is shown and page dies
function check_email ($email, $message){
// check if email exists
if ($email==""){die($message);}
// check whether email is correct (basic checking)
$test1=strpos($email, "@"); //value must be >1
$test2=strpos(substr($email,strpos($email,"@")), "."); //value must be >1
$test3=strlen($email); //value must be >6
$test4=substr_count ($email,"@"); //value must be 1
if ($test1<2 or $test2<2 or $test3<7 or $test4!=1){die($message);}
// check whether email is correct (advance checking)
// extracts whatever is after "@" to variable $email_server
$email_server=substr($email,strpos($email, "@")+1);
// Check DNS records (0 => the server exists; 1=> the server does not exist)
if (checkdnsrr($email_server)!=1){die ($message);}
}
// THIS FUNCTION WILL SHOW THE FORM
// MODIFY IT AS REQUIRED
function print_form(){
?>
<html>
<head>
<title></title>
</head>
<form action="<? $PHP_SELF; ?>" method="post">
<table>
<tr>
<td>
<input name="name" size="40" type="text" value="Name"> <br>
<input name="email" size="40" type="text" value="Email"> <br>
<div style="text-align: left;">
<input name="action" value="subc" checked="checked" type="radio">Subscribe
<input name="action" value="unsubc" selected="" type="radio">Unsubscribe
<br>
</div>
<div style="text-align: left;">
<input value="Submit" type="submit">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
} // the function finishes here
?>
<?
// to avoid showning errors (change to 1 to show them). For security
error_reporting(0);
// if info is posted, show the form and die
// the form is in the bottom of the page
if (!$_POST){print_form();die();}
// when info is posted you will be here
?>
<html>
<head>
<title></title>
</head>
<?
// SITE NAME
$site="yoursite.com";
//TITLE OF THE MAILINGLIST
$list_title="Title of the mailing list";
//SITE ADMIN NAME
$site_admin="name of site admin";
//Site admin e-mail
$site_admin_email="admin@yoursite.com";
//Message that will be sent to the user
$message="
Hi and welcome to the {$list_title}!
You have successfully subscribed with the following information:
Name: {$name}
Email: {$email}
test test test
test test test
test test test
http://downloadlink.com
If for any reason you do not want to receive any more emails from us, you can unsubscribe by removing your email address with this link: http://www.{$site}/email-list-script/emaillistscript.php
";
//Message headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$site_admin." ".$site."<".$site_admin_email.">\r\n";
// GET EMAIL
$email=$_POST["email"];
$name=$_POST["name"];
// To avoid problems, only lower case is used
$email=strtolower($email);
// Check whether email is correct by using a function
// function requires the email address and the error message
check_email ($email, "Email is not valid.");
// GET VALUE FOR action : subc (subscribe) or unsubc (unsubscribe)
$action=$_POST["action"];
// this is the file with the info (emails)
// When using the link in the top to download the complete script, a new name for this file
// will be generated (p.e.: emaillist-2ax1fd34rfs.txt), so users will be unable to find it
$file = "emaillist-subscribers.txt";
// lets try to get the content of the file
if (file_exists($file)){
// If the file is already in the server, its content is pasted to variable $file_content
$file_content=file_get_contents($file);
}else{
// If the file does not exists, lets try to create it
// In case file can not be created (probably due to problems with directory permissions),
// the users is informed (the first user will be the webmaster, who must solve the problem).
$cf = fopen($file, "w") or die("Error: file does not exits, and it cannot be created.<BR>Please check permissions in the directory or create a file with coresponding name.");
fclose($cf);
}
// IF REQUEST HAS BEEN TO SUBSCRIBE FROM MAILING LIST, ADD EMAIL TO THE FILE
if ($action=="subc"){
// check whether the email is already registered
if(strpos($file_content,"<$email>")>0){die("Your email is already included in this mailing list.");}
// write the email to the list (append it to the file)
$cf = fopen($file, "a");
fputs($cf, "\n$name <$email>"); // new email is written to the file in a new line
fclose($cf);
// notify subscription
print "Your information has been added. You will receive<br>an email with your subscription information shortly.";
mail($email,"$list_title",$message, "From: $site_admin_email");
}
// IF REQUEST HAS BEEN TO UNSUBSCRIBE FROM MAILING LIST, REMOVE EMAIL FROM THE FILE
if ($action=="unsubc"){
//code to fix unsubscribe error
function updateFile($fileName,$userName,$userEmail) {
$fp = '';
$myContent = '';
$fileContent = '';
$fp = fopen($fileName,'r');
if ($fp) {
while (!feof($fp)) {
$myContent = fgets($fp);
if ((preg_match("/$userEmail/",$myContent) == 1) && (preg_match("/$userName/",$myContent) == 1)) {
$myContent = '';
$fileContent = $fileContent.$myContent;
}
else {
$fileContent = $fileContent.$myContent;
}
}
fclose($fp);
$fp = fopen($fileName,'w');
if ($fp) {
fwrite($fp,$fileContent);
fclose($fp);
}
}
else {
die("\n Unable to open file.");
}
}
// notify unsubscription
print "Your email has been removed from our mailing list.";
}
?>
</body>
</html>
<?
// THIS FUNCTION WILL CHECK WHETHER AN EMAIL IS CORRECT OR NOT
// FIRST, BASIC ARCHITECTURE IS CHECKED
// THEM, EXISTANCE OF THE EMAIL SERVER IS CHECKED
// If email is not correct, the error message is shown and page dies
function check_email ($email, $message){
// check if email exists
if ($email==""){die($message);}
// check whether email is correct (basic checking)
$test1=strpos($email, "@"); //value must be >1
$test2=strpos(substr($email,strpos($email,"@")), "."); //value must be >1
$test3=strlen($email); //value must be >6
$test4=substr_count ($email,"@"); //value must be 1
if ($test1<2 or $test2<2 or $test3<7 or $test4!=1){die($message);}
// check whether email is correct (advance checking)
// extracts whatever is after "@" to variable $email_server
$email_server=substr($email,strpos($email, "@")+1);
// Check DNS records (0 => the server exists; 1=> the server does not exist)
if (checkdnsrr($email_server)!=1){die ($message);}
}
// THIS FUNCTION WILL SHOW THE FORM
// MODIFY IT AS REQUIRED
function print_form(){
?>
<html>
<head>
<title></title>
</head>
<form action="<? $PHP_SELF; ?>" method="post">
<table>
<tr>
<td>
<input name="name" size="40" type="text" value="Name"> <br>
<input name="email" size="40" type="text" value="Email"> <br>
<div style="text-align: left;">
<input name="action" value="subc" checked="checked" type="radio">Subscribe
<input name="action" value="unsubc" selected="" type="radio">Unsubscribe
<br>
</div>
<div style="text-align: left;">
<input value="Submit" type="submit">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
} // the function finishes here
?>
0 members, 1 guests, 0 anonymous users