Mailing List Script Help


#1

Hi, first time poster here

I have been looking at putting a newletter sign up form on my employers website.

I came across Eazy M@IL 2 which seemed to do exactly what I was looking for. I tested it on one of our hosted webservers and it worked fine, came to put it on the main hosted webserver and it wont run - doesn’t produce an error, just doesn’t work !

I contacted the web providers and the only differecne is the one that runs the code successfully has register_globals enabled, whereas the one that wont run it has register_globals disabled.

Could this be the cause of it? I understand enough PHP to interperate what the code is doing but not enough to troubleshoot issues like this.

The code is below

<?php $filename = "members.txt"; $fd = fopen ($filename, "r"); $contents = fread ($fd, filesize ($filename)); fclose ($fd); if(strstr($contents,$email)) { print "Your already subscribed to this mailing list."; } else { echo "Thank you $email for joining the mailing list, you should recieve a confirmation email from us within 5 minutes and you will get an email from us every week, blah"; if (!$save = fopen("members.txt","a")) { exit; } fwrite($save,"$emailrn"); fclose($save); if (!$save = fopen("names.txt","a")) { exit; } fwrite($save,"$namern"); fclose($save); mail("$email", "Compustorm Mailing List", "This email is to confirm that you have been added to the compustorm mailing list.", "From: MailList@compustorm.comrn" ."Reply-To: DONTEMAILBACK@compustorm.comrn" ."X-Mailer: PHP/" . phpversion()); } ?>

I have been to the website of the code creator and its just a ‘coming soon’ site with no contact details.

Any help much appreciated

Ian


#2

The register_globals could be causing the problem. It just depends on where you are getting $email from. If you are getting this value from a form you should have this at the top of the script:
[php]

<?php $email = $_POST['email']; ?>

[/php]


#3

I prefer

<?php $email = !empty($_POST['email']) ? $_POST['email'] : ''; ?>

And then if $email = ‘’ you can throw an error message.
This will also prevent an error from being displayed.

the ? is a tiernary operator (takes 3 arguments).

[b]Condition ? Value if True : Value if False[/b]