944,167 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1246
  • PHP RSS
Oct 26th, 2007
0

Newbie Needs Form Help

Expand Post »
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.'">';
?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esgdirect is offline Offline
5 posts
since Oct 2007
Oct 27th, 2007
0

Re: Newbie Needs Form Help

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:

php Syntax (Toggle Plain Text)
  1. mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
To:
php Syntax (Toggle Plain Text)
  1. mail($emailadd, $subject, $text, 'From: '.$emailfrom.'');
  2. //set your from address to $emailfrom
  3. //this will get its value from the form

To email both you and the user just add another mail function like:
php Syntax (Toggle Plain Text)
  1. mail($emailadd, $subject, $text, 'From: '.$emailfrom.''); //email admin
  2. mail($emailfrom, $subject, $text, 'From: '.$emailadd.''); //email user

HTH
StatiX
Reputation Points: 10
Solved Threads: 2
Light Poster
StatiX is offline Offline
32 posts
since Aug 2006
Oct 28th, 2007
0

Re: Newbie Needs Form Help

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
Attached Files
File Type: txt GLGHL_Representative_Contact_Form[1].txt (13.2 KB, 11 views)
File Type: txt SimpleScript1.txt (1.7 KB, 10 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esgdirect is offline Offline
5 posts
since Oct 2007
Oct 28th, 2007
0

Re: Newbie Needs Form Help

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:

php Syntax (Toggle Plain Text)
  1. mail($emailadd, $subject, $text, 'From: '.$Email.''); //email admin
  2. 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
Reputation Points: 10
Solved Threads: 2
Light Poster
StatiX is offline Offline
32 posts
since Aug 2006
Oct 28th, 2007
0

Re: Newbie Needs Form Help

Still the same. I still get the form but there is is still no return email address and the sender still gets no email.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esgdirect is offline Offline
5 posts
since Oct 2007
Oct 29th, 2007
0

Re: Newbie Needs Form Help

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_Represent...tact_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.
Last edited by esgdirect; Oct 29th, 2007 at 12:30 am. Reason: Adding a request for a different script.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esgdirect is offline Offline
5 posts
since Oct 2007
Oct 29th, 2007
0

Re: Newbie Needs Form Help

Add this code to the bottom of the .php script:
php Syntax (Toggle Plain Text)
  1.  
  2. echo '<META HTTP-EQUIV=Refresh CONTENT="30; URL='.$url.'">';
  3. echo "<b><br />emailadd var: " .$emailadd;
  4. echo "<br />subject: ".$subject;
  5. echo "<br />text: ".$text;
  6. echo "<br />from: ".$Email;
  7. echo "</b>";
  8.  
  9. ?>


Find out what the vars hold and post them. to see if its not getting set correctly
Reputation Points: 10
Solved Threads: 2
Light Poster
StatiX is offline Offline
32 posts
since Aug 2006
Oct 29th, 2007
0

Re: Newbie Needs Form Help

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esgdirect is offline Offline
5 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Displaying Mysql rows, alternate colors?
Next Thread in PHP Forum Timeline: PHP Prerequisite?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC