I have a simple Contact form script. I want to change it so it shows the email address of the person sending the form, not mine. I also hope I am pasting this code correctly. Sometimes I get a blank form, but all fields are required. I would like to know who is sending me the form. Also, how can the person sending the form get an email copy of what I receive? In case they entered something wrong? Thanks in advance.

Here is the code:

<?php


// Simple Form Script
// Copyright (C) 2005  Eric Zhang
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// Please send bugs/questions to erkzh@yahoo.com.


//--------------------------Set these paramaters--------------------------



$subject = 'Game Score Report';                // Subject of email sent to you.
$emailadd = 'bpavone@glghl.com';        // Your email address. This is where the form information will be sent.
$url = 'http://www.glghl.com/thank_you.html';               // Where to redirect after form is processed.
$req = '1';                                  // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.


// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = '  ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 45)
{echo "Name of form element $key cannot be longer than 45 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = '  ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Just edit the from field to show their email address. You will need to add another form element to your contact form then change the folowing code:

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

To:

mail($emailadd, $subject, $text, 'From: '.$emailfrom.''); 
//set your from address to $emailfrom 
//this will get its value from the form

To email both you and the user just add another mail function like:

mail($emailadd, $subject, $text, 'From: '.$emailfrom.''); //email admin
mail($emailfrom, $subject, $text, 'From: '.$emailadd.''); //email user

HTH
StatiX

Thanks for your quick reply. I appreciate that. I have attached the html in notepad of the form I use. And I attached a copy of the script with the changes you suggested. When I changed the code the way you told me to, I still receive the form, only there is no email address from the person sending it. It comes from "Unknown Sender" and then the sender of the form does not get an email copy of the form. Thanks in advance. Bill

From the contact form the user enters a value for their email and is stored in variable $Email. It looks like you just need to use it in your mail function like this:

mail($emailadd, $subject, $text, 'From: '.$Email.''); //email admin
mail($Email, $subject, $text, 'From: '.$emailadd.''); //email user

Note that the variable email is "Email" and not "email". If your server is linux or unix, the capital letter will make a difference.

Let me know how it goes

Regards,
StatiX

Still the same. I still get the form but there is is still no return email address and the sender still gets no email.

I want to add that the form has a .html extension and is not in the same file as the script. Obviously it is a simple script that was provided with the hosting I have through directadmin. I can change anything that is requested. The website is glghl.com and I have 2 forms on it. http://www.glghl.com/GLGHL_Representative_Contact_Form.html and http://www.glghl.com/GLGHL_Game_Score_Form.html

In a nutshell, I want the above attached form to be emailed to me and back to the person who sent it so they can see what they sent me. I also want it to come from their email address, so in case I get a blank form, which has happened 3 times already. I have no idea why. Right now it says I sent the form and if it comes in blank, I have no idea who sent it. I also have all fields required and it can stay that way. The reason I want them to receive an email is because I was told it gets complicated to do code to show them what they entered so they can then send after they check what they filled in.

This is for a hockey league I am running and need help as soon as I can get it. Thanks all in advance.

If someone has a different but simple script, I can change it to let me know.

Add this code to the bottom of the .php script:

echo '<META HTTP-EQUIV=Refresh CONTENT="30; URL='.$url.'">';
echo "<b><br />emailadd var: " .$emailadd;
echo "<br />subject: ".$subject;
echo "<br />text: ".$text;
echo "<br />from: ".$Email;
echo "</b>";

?>

Find out what the vars hold and post them. to see if its not getting set correctly

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
echo '<META HTTP-EQUIV=Refresh CONTENT="30; URL='.$url.'">';
echo "<b><br />emailadd var: " .$emailadd;
echo "<br />subject: ".$subject;
echo "<br />text: ".$text;
echo "<br />from: ".$Email;
echo "</b>";


It seemed to change and add the one line. Other than that I have no idea what you are talking about. Thanks again. I am going to look for a book to understand all this. I know html but thats it.