Page 1 of 1

Email submission php to the max

Posted: Wed Jun 18, 2008 6:18 am
by StupidIdiot
I know almost nothing about php (and only a small amount of html), but I'm making a website for my band (not that we'll be taking over the world any time soon), and need to use php for some things.

While the site is "under construction", I want to have a page up that allows visitors to input their email address so that I can email them when it is done, and also when we upload a new song etc etc.

I've called the page "index.htm" (because it'll be the main page up until the rest is done). In index.htm I have this:

Code: Select all

<form action="email.php" method="post"></form>
at the start of the input box. I don't know if this is right...

Then for "email.php" I have:

Code: Select all

<?php
$email_list = ("email.txt");
$emails = file($email_list);
$fp = fopen($email_list , "a");
fputs($fp , "$new_email");
fclose($fp);
?>
I don't know what's going on really, just robbed it from various tutorials.

How do I assign the variable "$new_email" to the email address that has just been entered? So when someone enters their email I want it to equal $new_email.
Also are email.php and index.htm even right?

Any help is very much appreciated

Re: Email submission php to the max

Posted: Wed Jun 18, 2008 6:41 am
by WebbieDave
Change index.html to:

Code: Select all

<form action="email.php" method="post">
    <input type="text" name="new_email">
    <input type="submit" value="Join Mailing List">
</form>
On email.php, replace line 3 (you don't need to use the file() function in this script) with:

Code: Select all

$new_email = $_REQUEST['new_email'];
Change line 5 to:

Code: Select all

fputs($fp , "$new_email\n");
Keep rockin...

Re: Email submission php to the max

Posted: Wed Jun 18, 2008 1:27 pm
by StupidIdiot
Thanks hugely Dave, I was like this :? right, then eventually I was giving it :banghead:, but now thanks to you I'm :drunk: (with happiness).

Made good use of smilies there