...

View Full Version : One more try - simple 'registration' script



kargrafx
11-15-2006, 09:22 AM
Okay, I was mislead as to what serverside language(s) were available when I first started asking about this; so I have posted first in javascript (thinking none were available) and then in CGI/Perl (thinking PHP was not available). I now know the truth, and would prefer a PHP solution. I apologize for cross-posting the request, it was not intentional...

I have a friend who wants to collect email addresses from visitors to his website. He really isn't looking for security, but is more interested in collecting emails and simple contact information. Is there an easy way to have a short form which collects that info, then sends a password which they can use to log in?

specifically, I would like the following to occur...

>A form is filled out, requiring four fields, "Name", "Email", "Phone Number", and an "Opt-In/Out" checkbox.
>The user submits the form, and two emails are sent.
->One is sent to (admin@site.com) with the form field info.
->The other is sent to the address from form field 'Email', and is a pre-written email with a password to access the site.

So I start with a simple form...


<form method='post' action='<?php echo $PHP_SELF;?>'>
Name:<input type='text' size='20' name='name'><br />
Email:<input type='text' size='20' name='email'><br />
Phone Number:<input type='text' size='20' name='phone'><br />
By selecting this box you are signing up for our email list.<br />
Yes, keep me notified!:<input type='checkbox' value='optin' name='optin'><br />
<input type="submit" name="submit" value="submit">
</form>


I then create the PHP to parse the form...


<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$optin = $_REQUEST['optin'];
$body = $name./n.$email./n.$phone./n.$optin

mail ('admin@site.com', 'new registration', $body)
mail ($email, 'Password', 'The password for www.site.com is password.')
?>


I then tied it together as follows...



<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$optin = $_REQUEST['optin'];
$body = $name./n.$email./n.$phone./n.$optin

if (!isset($_REQUEST['submit'])) {
>?
<html><head></head><body>
<form method='post' action='<?php echo $PHP_SELF;?>'>
Name:<input type='text' size='20' name='name'><br />
Email:<input type='text' size='20' name='email'><br />
Phone Number:<input type='text' size='20' name='phone'><br />
By selecting this box you are signing up for our email list.<br />
Yes, keep me notified!:<input type='checkbox' value='optin' name='optin'><br />
<input type="submit" name="submit" value="submit">
</form></body>
<?
} else {

mail ('admin@site.com', 'new registration', $body)
mail ($email, 'Password', 'The password for www.site.com is password.')
?>
<html><head></head><body>
Thank you for registering, you will receive a password in your email shortly.
</body>
<?
}
?>

I know it is very crude, but I want to start as simple as possible as the entire site will be redesigned in a short time. The above does not seem to work for me, though; it only returns a blank webpage (source below). I tested a basic php mail test, so I know it works.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

for example, mail ('me@site.com', 'test', 'test message') sent the email with subject 'test' and body 'test message'.

So obviously, even as simple as I tried to keep it, I screwed up somewhere. Any help?

Spookster
11-15-2006, 09:43 AM
I'm about to go to bed but i've attached an example of pretty much the same thing. This was something I wrote for a client's site I was working on. It is simply a way for a customer to provide some personal info to the store staff. It's pretty basic but it might help.

Yawnnnn!!!! Good night. :D

GSimpson
11-15-2006, 10:06 AM
also make sure your server supports the "php mail function". Some servers do not however they support SMTP and my offer a certain amount of mail accounts.

Latley i've been into the whole mail script thing to because of a lost password thing and I found that was my problem.

Just to be sure, check that out.

kargrafx
11-15-2006, 10:16 AM
I edited the above as I caught a couple of glaring errors in the code myself. But the errors seem to have nothing to do with the problem at hand; I still have nothing but a blank page on loading it.

I have tested the mail() function, and it works fine. I am thinking it is something to do with the if (!isset($_REQUEST['submit'])) { bit, trying to use a single page to display the form, send the emails, and display the confirmation.

But I have no idea how to fix that... :(

GSimpson
11-15-2006, 10:18 AM
im going to be honset, I would probably just create a new folder then just have index.php and send.php so that its still neat and tidy and you get the job done.

Alex!
11-15-2006, 10:30 AM
Hi,
I've redone ur script so it should now work.



<html><head></head><body>
<?php
if(isset($_POST['submitted'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$optin = $_POST['optin'];
$body = "
Name: $name
Email: $email
Phone Number: $phone
Optin : $optin";

mail ($email, 'Password', 'The password for www.site.com is password.', 'From: YourSite.com') &&
mail ('you@yoursite.com', 'new registration', $body, 'From: '.$name.'<'.$email.'>');

echo 'Thankyou for signing up to our website!';
} else {
echo '


<form method="post" action="mail-form.php">
Name:<input type="text" size="20" name="name"><br />
Email:<input type="text" size="20" name="email"><br />
Phone Number:<input type="text" size="20" name="phone"><br />
By selecting this box you are signing up for our email list.<br />
Yes, keep me notified!:<input type="checkbox" name="optin"><br />
<input type="submit" name="submitted" value="Sign Up!"></input>
</form> ';
}

?>
</body>
</html>

However, you may want to put in some validation in there somewhere.

Hope this helps

Alex:thumbsup:

kargrafx
11-15-2006, 10:33 AM
so you would reccomend (since I am tired, and not that good even when fully alert)...

index.html:



<HTML><head></head><body>
<form method='post' action='send.php'>
Name:<input type='text' size='20' name='name'><br />
Email:<input type='text' size='20' name='email'><br />
Phone Number:<input type='text' size='20' name='phone'><br />
By selecting this box you are signing up for our email list.<br />
Yes, keep me notified!:<input type='checkbox' value='optin' name='optin'><br />
<input type="submit" name="submit" value="submit">
</form></body>

and send.php:



<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$optin = $_REQUEST['optin'];
$body = $name./n.$email./n.$phone./n.$optin

mail ('admin@site.com', 'new registration', $body)
mail ($email, 'Password', 'The password for www.site.com is password.')
?>
<html><head></head><body>
Thank you for registering, you will receive a password in your email shortly.
</body>

kargrafx
11-15-2006, 10:34 AM
thanks alex, you posted while I was responding to the last post, lol. I will try that now.

Alex!
11-15-2006, 10:39 AM
i forgot to point out that you'll have to call the form mail-form.php or change the action of the form. ;)

Alex

kargrafx
11-15-2006, 10:49 AM
Thanks, this works fine. Validation will be a worry with the next version of the site - for now, if they don't enter the right email address, they simply don't get into the site. There will be a bit of spam to the admin, but it shouldn't be a huge issue.

I did see that, even in my tired state I was alert enough to catch the action change.

Again, THANKS!:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum