11Tami Posted January 4, 2007 Share Posted January 4, 2007 Hello, this cool code someone gave me. If you save this in notepad and change the email under "uncomment the following line" to your own email address. Then enter items into the fields and send. For some reason it automatically inserts your own email account into the subject field. Can anyone tell me how this cool form code does this? I need to know how it works this way so I can modify accordingly. Thanks a lot.<?php require_once 'thisform.php';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title>Forms</title></head><body><?php if (isset($_POST['Submit']) && isset($_POST['fieldname']) && trim($_POST['fieldname']) != '' && $_POST['groupname'] != '') { echo '<h1>Thank you for filling out this form!</h1>'; $text = ''; foreach ($_POST as $name => $value) { if (is_array($value)) { $text .= sprintf("%s: %s\n", $name, join(' ', $value)); } else { $text .= sprintf("%s: %s\n", $name, $value); } } // UNCOMMENT THE FOLLOWING LINE TO USE ON YOUR SITE mail('youremailaddress', 'Form data', $text); } else {?> <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>"> <input type="text" name="fieldname" value="<?php echo (isset($_POST['fieldname'])) ? htmlspecialchars($_POST['fieldname']) : ''; ?>" /><br /> <input type="radio" name="groupname" value="php3" <?php if (isset($_POST['groupname']) && $_POST['groupname'] == 'php3') { echo 'checked="checked" '; } ?>/>PHP 3 <input type="radio" name="groupname" value="php4" <?php if (isset($_POST['groupname']) && $_POST['groupname'] == 'php4') { echo 'checked="checked" '; } ?>/>PHP 4 <input type="radio" name="groupname" value="php5" <?php if (isset($_POST['groupname']) && $_POST['groupname'] == 'php5') { echo 'checked="checked" '; } ?>/>PHP 5<br /> <input type="submit" name="Submit" /> </form><?php }?></body></html> Quote Link to comment Share on other sites More sharing options...
taith Posted January 4, 2007 Share Posted January 4, 2007 i'd say it'd be something automatic from the mail server, not from the php itself... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.