I have a website where I have two text boxes for information entry. My "Submit" Button orders a PHP file to take the information in the two text boxes and copy/paste it into a text file named "Members.txt" The purpose is to take the information from the text boxes and create a mailing list. Now my problem is that I know the PHP file is calling for the text file because each time I hit submit, i can see on my ftp that the text file has been edited at the same time I try to submit to be apart of the list. In additon, the text file Is attempting to place the information into the text file as I can see that every time the "Submit" button is hit, the Text files entry lines are lower and lower. In otherwords a complete line is entered. but no text. And no, the text is not white. What am I doing wrong?
<h2>Join our Mailing List</h2>
<form method="post" action="add.php" name="signup">
<input type="hidden" name="pommo_signup" value="true" />
<table border="0" bordercolor="#000000"
bordercolordark="#000000" bordercolorlight="#000000">
<tr>
<td width="203" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> NAME: <font size="4">
<input name="name"
type="text" size="20" maxlength="100" />
</font></td>
</tr>
<tr>
<td height="26" bgcolor="#FFFFFF"> EMAIL: <font size="4">
<input name="email"
type="text" size="20" maxlength="100" />
</font></td>
</tr>
<tr>
<td height="31" bgcolor="#FFFFFF"><span style="text-align: left"></span><p align="middle">
<input type="image" src="ok.jpg" />
</p></td>
</tr>
</table>
</form>
THEN BELOW IS THE FORM THAT IS SUPPOSED TO ADD TO THE TEXT BOX.
<?php
$filename = "members.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
if(strstr($contents,$email)) {
print "You're already subscribed to this mailing list.";
}
else {
echo "Thank you $email for joining the mailing list";
if (!$save = fopen("members.txt","a")) {
exit;
}
fwrite($save,"$email
");
fclose($save);
if (!$save = fopen("names.txt","a")) {
exit;
}
fwrite($save,"$name
");
fclose($save);
mail("$email", "Fairview HiFi News Letter", "Welcome to the Fairview HiFi mailing list. Your exclusive source for product and promotional news and events.",
"From: Newsletter@FairviewHiFi.com
"
."Reply-To: NOREPLY@FairviewHiFi.com
"
."X-Mailer: PHP/" . phpversion());
}
?>
Use $_POST['email']
not $email
.
Your server has disabled register globals, which means that form inputs (and GET vars) aren't automatically avaliable in the form of $formFieldName
, so you have to use $_POST/GET/COOKIE/...
And don't change this setting, it's a huge security hole if you enable register globals.
Posted variables need to be referenced via $_POST
. So your email will be:
print $_POST["email"];
And not merely $email
. Additionally, since you're appending new lines, you might find a less-verbose solution to be appealing. See file_put_contents()
with the FILE_APPEND
flag:
<?php
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith
";
// Append the contents of $person to the file named by $file.
file_put_contents($file, $person, FILE_APPEND);
?>
there are several open source alternatives to creating your own mailing list. Creating an industrial scale mailing list application is a non trivial task. If you want php mailing list scripts you can check out either of the following options. PHPList( http://www.phplist.com) Pros- • Its has built in email templates with a powerful WYSIWYG editor which makes creating and deploying newsletter applications a breeze even for someone with no prior php programming experience. • Furthermore it also supports features such as RSS,List segmentation ,click tracking ,attachments bounce management etc. Cons- • Buggy and difficult to customize UI • Difficult to customize the look and feel of the UI to match that of the existing website
poMMO(http://www.pommo.org) Pros • It is very easy to match the look and feel of the subscription form to that of the existing website or embed the subscription form to an existing webpage. • WYSIWYG HTML mailing editor • It also provides a limit of sending of mails and provides an option of throttle by hour ,bytes or domain limits. • Provides localization and support for 10 other languages besides English
OpenEMM(http://www.openemm.org)
Pros • Sophisticated features not seen in other open source email subscription lists managers such as bounce management, link tracking, real time statistics and support for scripting. • Uses and supports leading java frameworks such as Hibernate, Spring and Struts.
Cons- • Huge code base which may cause slower page load times. • Might be considered overkill if only a basic email newsletter management is required. • Might not be supported by all web servers.