NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Form help - beginner :(

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 11-08-2005, 08:14 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Nov 2004
Posts: 60
neilfahey is an unknown quantity at this point
 



PHP Form help - beginner :(


Hey everyone,

I've got a simple PHP mail form working on the intranet at work but now I want to customize it for our use. Basically it's going to be a form that teachers can fill in when there is a lock-down (drill or otherwise) to inform the necessary people that they are okay.

The script consists of two files - sendeail.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Sendemail Script</title>
????: NamePros.com http://www.namepros.com/programming/138666-php-form-help-beginner.html
</head>
<body>

<!-- Required: YOUR email ($myemail). Optional: Enter CC email address ($ccx) 
Required: Add the link for the 'next page' (at the bottom) --> 

<?php

$myemail 
"nl@greenvaleps.vic.edu.au"
$ccx ""

if(!
$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{
echo 
"<h2>Use Back - Enter valid e-mail</h2>\n"
$badinput "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty(
$visitor) || empty($visitormail) || empty($notes )) {
echo 
"<h2>Use Back - fill in all fields</h2>\n";
}
echo 
$badinput;

$todayis date("l, F j, Y, g:i a") ;

$attn $attn "(" $ccopy ")" 
$subject $attn

$notes stripcslashes($notes); 

$message $todayis [EST] \n
Attention: 
$attn \n
Message: 
$notes \n 
From: 
$visitor ($visitormail)\n
Additional Info : IP = 
$ip \n
Browser Info: 
$httpagent \n
Referral : 
$httpref \n
"
;

$from "From: $visitormail\r\n";

if ((
$ccopy == "ccyes") && ($visitormail != "")) 
mail($visitormail$subject$message$from);

if (
$myemail != ""
mail($myemail$subject$message$from);

if (
$ccx != ""
mail($ccx$subject$message$from);

?>

<p align="center">
Date: <?php echo $todayis ?> 
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
<br />

Attention: <?php echo $attn ?>
<br /> 
Message:<br /> 
<?php $notesout str_replace("\r""<br/>"$notes); 
echo 
$notesout?> 
<br />
<?php echo $ip ?> 

<br /><br />
<a href="contact.php"> Next Page </a> 
</p> 

</body>
</html>

...and contact.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Form </title>
</head>
<body>

<form method="post" action="sendeail.php">

<!-- DO NOT change ANY of the php sections -->
<?php
$ipi 
getenv("REMOTE_ADDR");
$httprefi getenv ("HTTP_REFERER");
$httpagenti getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input type="text" name="visitor" size="35" />
<br />
Your Email:<br />
<input type="text" name="visitormail" size="35" />
<br /> <br />
All Students Accounted For ? No
<input name="ccopy" type="radio" value="ccno" />   Yes<input checked="checked" name="ccopy" type="radio" value="ccyes" /> <br /> 

<br />
Attention:<br />
<select name="attn" size="1">
<option value=" Sales n Billing ">Sales n Billing </option> 
<option value=" General Support ">General Support </option> 
<option value=" Technical Support ">Technical Support </option> 
????: NamePros.com http://www.namepros.com/showthread.php?t=138666
<option value=" Webmaster ">Webmaster </option> 
</select>
<br /><br />
Mail Message:
<br />
<textarea name="notes" rows="4" cols="40"></textarea>
<br />
<input type="submit" value="Send Mail" />
<br />

<!-- Free Code at: http://www.ibdhost.com/contact/ --> 

</form>

</body>
</html>
So what I need to do is listed below:

- Rather than the user inputting their e-mail address, I need it to always send FROM a specified address (eg. ld@gv.edu.au)

- The 'Your Name' field needs to display in the 'Subject:' header of the resulting e-mail

- Where it says 'All Students Accounted For?' was actually a 'CC:' option but I just need it to list the YES or NO answer in the resulting e-mail

- I also want to add a couple more multi-line text boxes where they can add names of missing students and other staff in the classroom

I think that's about it... I'm sorry but I have NO IDEA where to start! Can somebody help me?

Thanks heaps in advance!
Neil

EDIT: Removed e-mail address
Last edited by neilfahey; 11-08-2005 at 11:26 PM.
neilfahey is offline  
Old 11-08-2005, 09:40 PM   #2 (permalink)
Account Suspended
 
Andromeda's Avatar
Join Date: Aug 2005
Posts: 862
Andromeda is on a distinguished road
 



You eman you are looking for someone to hire?
Andromeda is offline  
Old 11-08-2005, 10:23 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Nov 2004
Posts: 60
neilfahey is an unknown quantity at this point
 



I didn't realise it would be that much work? I thought someone could just give me a quick tip... Sorry about that! I can give ya $74 namebucks but you'll have to tell me how (Thats what people do isn't it? I don't even know what they are!)

Maybe I'll look around the web for more help and come back when I've got more specific questions....

Cheers
Neil
neilfahey is offline  
Old 11-09-2005, 06:36 AM   #4 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 563
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



The PHP mail() command takes four parameters:

mail(<email address where it is going to>, <subject>, <body of email>, <additional headers>);


All you need to do is alter the variables that you need. For example, to alter what the subject looks like, all you need to do is adjust this lines accordingly:

$attn = $attn . "(" . $ccopy . ")" ;

The same goes for the other things.

-Bob
__________________
Want a way to monitor your website against hacking? Check out CrossCheck.net
moondog is offline  
Old 11-09-2005, 03:02 PM THREAD STARTER               #5 (permalink)
NamePros Member
Join Date: Nov 2004
Posts: 60
neilfahey is an unknown quantity at this point
 



Thanks Moondog! That's a great start... I'll have a crack at it now.
neilfahey is offline  
Old 11-09-2005, 03:52 PM   #6 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Is this sort of what you are looking for?

mail.php

PHP Code:
<html>
<head>
<title></title>
</head>

<body>

<form method="post" action="mail.php">
Name:&nbsp;<input type="text" name="name">
<br>
All students accounted for?&nbsp;
<select name="accounted_for">
<option name="Yes">Yes</option>
<option name="No">No</option>
</select>
<br>
<br>
Missing:
<br>
<textarea name="missing" rows="15" cols="65"></textarea>
<br>
<br>
<input type="submit" name="submit" value="Submit">
</form>

<?php

if(isset($_POST['submit']))
{
  
$name trim(stripslashes($_POST['name']));
????: NamePros.com http://www.namepros.com/showthread.php?t=138666
  
$all_students $_POST['accounted_for'];
????: NamePros.com http://www.namepros.com/showthread.php?t=138666
  
$missing trim(stripslashes($_POST['missing']);
  
  
$date date("m/d/Y");
  
$ip $_SERVER['REMOTE_ADDR'];
  
  
$headers "From: ld@gv.edu.au";
  
  
mail("emailtosendto@domain.com""$name""
  
  From: 
$name
  
  All students accounted for?
  
$all_students
  
  Missing:
  
  
$missing

  IP Address:
  
$ip
  
  Date Sent:
  
$date

  "
$headers);
  
  if(!
mail)
  {
    echo 
'Mail sent.';
  }
  else
  {
    echo 
'Seems to have been a problem, mail could not be sent.';
  }
}
?>

</body>
</html>
Eric is offline  
Old 11-09-2005, 06:59 PM THREAD STARTER               #7 (permalink)
NamePros Member
Join Date: Nov 2004
Posts: 60
neilfahey is an unknown quantity at this point
 



Darn it! That'll teach me to check my e-mail more often! That looks pretty good but blissfully unaware, I've been having a crack at it myself... Here's what I came up with: (THANKYOU HEAPS SecondVersion FOR YOUR POST!)

sendeail.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Sendemail Script</title>
</head>
<body>

<!-- $myemail is the address that lockdown reports will go to --> 

<?php

$myemail 
"nl@grelpsl.edu.au"
$ccx ""

if(empty(
$name) || empty($grades) || empty($missing )) {
echo 
"<h2>Use Back - fill in all fields</h2>\n";
}


$todayis date("l, F j, Y, g:i a") ;

$subject $name

$missing stripcslashes($missing); 

$message $todayis [EST] \n
Staff Member Submitting Form: 
$name \n
Grade(s): 
$grades \n
All Students Accounted For?  
$acc \n
Missing Students: 
$missing \n 
Names of Others In Classroom (eg. Support Staff, Visitors, Parents, Tradesmen): 
$other \n
"
;

$from "From: $name \r\n";



if (
$myemail != ""
mail($myemail$subject$message$from);

if (
$ccx != ""
mail($ccx$subject$message$from);

?>

<p align="center">
<strong>Thankyou <?php echo $name ?> 
<br />
<br />
You sent the following results:</strong><br />
<br />
<strong>Grade(s):</strong> <?php echo $grades ?>
<br />
<br />
<strong>All Students Accounted For?</strong> <?php echo $acc ?>
<br />
<br /> 
<strong>Missing Students:</strong><br /> 
<?php echo $missing ?> 
<br />
<br />
<strong>Names of Others In Classroom (eg. Support Staff,<br />
Visitors, Parents, Tradesmen):</strong> <?php echo $other ?><br />
<br />
<strong>Date &amp; Time Sent:</strong> <?php echo $todayis ?>

<br /><br />
<a href="http://10.77.81.13:81"> Home </a> 
</p> 

</body>
</html>


contact.php
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lockdown Form</title>
</head>
<body>

<form method="post" action="sendeail.php">

<!-- DO NOT change ANY of the php sections -->
<?php
$ipi 
getenv("REMOTE_ADDR");
$httprefi getenv ("HTTP_REFERER");
$httpagenti getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input name="name" type="text" id="name" size="35" />
<br />
<br />
Grade(s):<br />
<input name="grades" type="text" id="grades" size="35" />
<br /> <br />
All Students Accounted For ? No
<input name="acc" type="radio" value="No" />   
Yes<input checked="checked" name="acc" type="radio" value="Yes" /> 
<br />
<br /> 

Names of Missing Children:
<br />
<textarea name="missing" cols="40" rows="4" id="missing"></textarea>
<br />
<br />
Names of Others In Classroom (eg. Support

Staff,<br /> 
Visitors, Parents, Tradesmen):<br />
<textarea name="other" cols="40" rows="4" id="other"></textarea>
<br />
<br />
<input type="submit" value="Send Mail" />
<br />

<!-- Free Code at: http://www.ibdhost.com/contact/ --> 

</form>

</body>
</html>

This is actually doing EVERYTHING I want it to do now except for two things...

- I want the From: field of the resulting e-mail to display either the real address that it comes from or just 'Lockdown Report'... Currently it comes up with name@someobscuredomain.edu.au (where name is what the user has typed as their name)

- I was also wondering if it was possible to tabulate the resulting e-mail or at least bold the answers to the questions, so the person who receives the e-mail isn't sifting through it all
????: NamePros.com http://www.namepros.com/showthread.php?t=138666

Hope that's clear enough... Can anyone help?
Thanks
Neil

PS. Thanks again to moondog for getting me started!! Thankfully I've got a little bit of a grounding in programming (from 10 or more years ago) so I was able to figure most things out from there!
????: NamePros.com http://www.namepros.com/showthread.php?t=138666

Just found another problem I'm having trouble with too...

If you leave a field blank and click 'Submit' it tells you to go back and fill in all fields, but it still sends the e-mail! Is there any way I can tell it not to send the e-mail in this case?

Thanks again,
Neil
neilfahey is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP search form Barrucadu Programming 18 08-11-2005 09:12 AM
Populate a dropdown for PHP form static1635 Programming 6 08-10-2005 04:32 AM
We customize form for your website at very good price. shrekwarrior Web Development Wanted 0 03-25-2005 08:05 PM

 
All times are GMT -7. The time now is 02:03 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger