Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 7 of 7
  1. #1
    Platinum Lifetime Member

    Join Date
    Jun 2005
    Posts
    539
    DNF$
    10,653
    Bank
    0
    Total DNF$
    10,653
    Donate  

    My first lil script...and problems :p

    Okay
    i finally created a useless script and i am facing some problems

    so basically its an anonymous emailer

    here is the code

    email.html
    Code:
    <form action="mail.php" method="post">
    Your Name: <input type="text" name="name" size="20"><br>
    E-mail: <input type="text" name="email" size="20"><br><br>
    To: <input type="text" name="id" size="20"><br>
    Subject: <input type="text" name="subject" size="20"><br>
    Comments<br>
    <textarea name="comments" rows="1" cols="20"></textarea><br><br>
    <input type="submit" value="Submit">
    </form>
    mail.php
    Code:
    <?
    /***************************************************************************
     *                           mail.php
     *                            -------------------
     *   Version              : 0.1
     *   email                : unknowngiver@gmail.com
     * Warning:              Dont copy my source or fbi will kick ur ass
     ***************************************************************************/
    
    $name=$_POST['name'];
    $email=$_POST['email'];
    $header=$_post['subject'];
    $comments=$_POST['comments'];
    $to=$_POST['id'];
    $message=$comments;
    if(mail($to,$header,$message,"From: $email\n")) {
    echo "Thanks for your comments.";
    } else {
    echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
    }
    ?>

  2. #2
    Web Guru

    Join Date
    Apr 2003
    Location
    Connecticut
    Posts
    208
    DNF$
    2,104
    Bank
    0
    Total DNF$
    2,104
    Donate  

    Re: My first lil script...and problems :p

    You didn't say exactly what was not working with your script.

    Anyways, here's a tutorial I wrote recently about mail forms, it should help (feel free to use it, just don't paste your header on it)
    Better Contact Forms

    What I think never occurs to people is that $_GET and $_POST are arrays. Every time someone shows me a contact form, it has line after line of written-out $_POST variables.

    The first part to understand is the foreach function. Foreach loops through an array, and allows a script to access each variable in succession.

    Example code:
    PHP Code:
        <?php
            
    foreach($_POST as $key => $value)
            {
                
    $message .= $key.' was set to: '.$value."\n";
            }
        
    ?>
    In the above example, $key and $value are made available in each loop. $_POST['name'] = 'Dan' would technically look like $_POST[$key] = $value. This makes it easy to append the values to our message.

    The rest of the script is cake:

    PHP Code:
        <?php
            $email 
    'myname@example.com';
            
    $subject $_POST['subject'];
            foreach(
    $_POST as $key => $value)
            {
                
    $message .= $key.' was set to: '.$value."\n";
            }
            
    mail($email,$subject,'From: AutoMailer <noreply>');
        
    ?>
    A bonus is that this code is reusable, so creating contact forms becomes as easy as copy and paste.

  3. #3
    Platinum Lifetime Member

    Join Date
    Jun 2005
    Posts
    539
    DNF$
    10,653
    Bank
    0
    Total DNF$
    10,653
    Donate  

    Re: My first lil script...and problems :p

    I didnt really get this

    foreach($_POST as $key => $value)

  4. #4
    David Ausman
    DavidAusman's Avatar
    Join Date
    May 2005
    Location
    127.0.0.1
    Posts
    853
    DNF$
    1,494
    Bank
    0
    Total DNF$
    1,494
    Donate  

    Re: My first lil script...and problems :p

    Use online form generator if you dont know how to do it

  5. #5
    Platinum Lifetime Member

    Join Date
    Jun 2005
    Posts
    539
    DNF$
    10,653
    Bank
    0
    Total DNF$
    10,653
    Donate  

    Re: My first lil script...and problems :p

    hm guys read the whole thing please
    i am learning php and i just tried making a small annoynamous emailer
    its not a CONTACT FORM

    read it!!!!! geez

    I just want to know wht i did wrong? Why isnt it showing the "SUBJECT" in the real email

  6. #6
    Gold Lifetime Member
    CNerd2025's Avatar
    Join Date
    Aug 2004
    Posts
    3
    DNF$
    193
    Bank
    0
    Total DNF$
    193
    Donate  

    Re: My first lil script...and problems :p

    The first thing I'd do is use variable names that are identical to the form names. It is easier to debug when $subject gets $_POST['subject'] instead of $header getting $_POST['subject'].
    The second thing is that foreach($foo as $bar) is a loop. It takes an array $foo and assigns the current index to the variable $bar,performs the statements, and then increments the index.
    The third thing is that PHP is case sensitive. $_post['subject'] is a different (and undefined variable) from $_POST['subject']. The rewritten code is below.

    If you don't know about certain functions or about certain PHP structures, look at the PHP manual on PHP.net. It has a complete function reference and is a great resource.
    Code:
    <?
    /**************************************************  *************************
     *                           mail.php
     *                            -------------------
     *   Version              : 0.1
     *   email                : unknowngiver@gmail.com
     * Warning:              Dont copy my source or fbi will kick ur ass
     **************************************************  *************************/
    
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $comments=$_POST['comments'];
    $id=$_POST['id'];
    {
    mail($id,$subject,$comments,"From: $email");
    echo "Thanks for your comments.";
    }
    or die("There was a problem sending the mail. Please check that you filled in the form correctly.");
    
    ?>
    --Drew

    P.S. This isn't any unique code; although you may want to "reserve your rights" as a copyright holder, this code has been written and rewritten many times: you have no idea. Don't bother with it. And also, don't get pissed off when people respond to your posts. It's bad etiquette toward those who are offering to help you. Such behavior only makes you look like a dumbass. Remember the old mantra, "don't kill the messenger."
    Last edited by CNerd2025; 07-25-2005 at 08:04 PM. Reason: Grammar

  7. #7
    Web Guru

    Join Date
    Apr 2003
    Location
    Connecticut
    Posts
    208
    DNF$
    2,104
    Bank
    0
    Total DNF$
    2,104
    Donate  

    Re: My first lil script...and problems :p

    CNerd has it right.

    Also my code works fine, you could have just replaced the $email variable with $_POST['email'].

    What foreach does is look through all values in an array, and $_POST is an array of variables sent via a form.

Bookmarks

Posting Permissions

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

Domain name forum recommended by Domaining.com