DNforum.com - Domain Sales, Domain Forum, Domain Appraisals
 
Register Now! Welcome to Dnforum.com You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast and simple so please, join our community today! If you have any problems with the registration process or your account login, please contact us.
Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Reply
 
LinkBack Thread Tools Display Modes
Old 07-22-2005, 10:15 AM   #1 (permalink)
Platinum Lifetime Member
 
Last Online: 04-18-2008 05:49 PM
iTrader: (11)
Join Date: Jun 2005
Posts: 524
DNF$: 2,486


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 ***
 ***************************************************************************/

$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.";
}
?>
__________________
Bookmark!
unknowngiver is offline   Reply With Quote
Old 07-22-2005, 02:08 PM   #2 (permalink)
Web Guru
 
Name: Dan
Last Online: Yesterday 06:51 PM
iTrader: (5)
Join Date: Apr 2003
Posts: 207
DNF$: 1,929
Location: Connecticut
Country:


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)
Quote:
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.
dotDan is offline   Reply With Quote
Old 07-25-2005, 07:47 PM   #3 (permalink)
Platinum Lifetime Member
 
Last Online: 04-18-2008 05:49 PM
iTrader: (11)
Join Date: Jun 2005
Posts: 524
DNF$: 2,486


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

I didnt really get this

foreach($_POST as $key => $value)
__________________
Bookmark!
unknowngiver is offline   Reply With Quote
Old 07-25-2005, 07:57 PM   #4 (permalink)
David Ausman
 
DavidAusman's Avatar
 
Last Online: 07-07-2008 04:14 PM
iTrader: (40)
Join Date: May 2005
Posts: 822
DNF$: 848
Location: 127.0.0.1


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

Use online form generator if you dont know how to do it
__________________
Best Regard
~ David Ausman
DavidAusman is offline   Reply With Quote
Old 07-25-2005, 08:20 PM   #5 (permalink)
Platinum Lifetime Member
 
Last Online: 04-18-2008 05:49 PM
iTrader: (11)
Join Date: Jun 2005
Posts: 524
DNF$: 2,486


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
__________________
Bookmark!
unknowngiver is offline   Reply With Quote
Old 07-25-2005, 09:03 PM   #6 (permalink)
Gold Lifetime Member
 
CNerd2025's Avatar
 
Last Online: 08-05-2005 11:52 AM
iTrader: (0)
Join Date: Aug 2004
Posts: 3
DNF$: 112


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 ***
 **************************************************  *************************/

$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 09:04 PM. Reason: Grammar
CNerd2025 is offline   Reply With Quote
Old 07-28-2005, 07:20 PM   #7 (permalink)
Web Guru
 
Name: Dan
Last Online: Yesterday 06:51 PM
iTrader: (5)
Join Date: Apr 2003
Posts: 207
DNF$: 1,929
Location: Connecticut
Country:


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.
dotDan is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 05:17 AM.
Copyright @2001-2008 DNForum.com

Learn Domains
Promote Domains
Research Domains
Buy Domains
Resell Domains
Park Domains
Sell Domains
Build Domains
Host Domains
Trademark Domains
Domain Domains
manage Domains
Appraise Domains