Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation One more try - simple 'registration' script

    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...

    Code:
    <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...

    Code:
    <?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 Code:
    <?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 />
    Yeskeep 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 [url]www.site.com[/url] 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.
    Code:
    <!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?
    Last edited by kargrafx; 11-15-2006 at 09:10 AM.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Attached Files Attached Files
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #5
    Regular Coder GSimpson's Avatar
    Join Date
    Aug 2006
    Location
    New Zealand
    Posts
    268
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.
    The internet is my Sandbox, and notepad is my Spade n' Bucket.

  • #6
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I've redone ur script so it should now work.

    PHP Code:
    <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
    Last edited by Alex!; 11-15-2006 at 09:32 AM.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so you would reccomend (since I am tired, and not that good even when fully alert)...

    index.html:

    Code:
    <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 Code:
    <?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>

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks alex, you posted while I was responding to the last post, lol. I will try that now.

  • #9
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i forgot to point out that you'll have to call the form mail-form.php or change the action of the form.

    Alex

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •