Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change feedback form script

Status
Not open for further replies.

multichild

Programmer
Jan 28, 2006
76
GB
I am completely new to PHP and so starting right at the beginning.

I am putting together a form, and have it working no worries, but I wont to include more details in the feedback form that goes to the website owner.

The code im using is below:

<?
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
mail("info@hobbsvalve.co.uk", "Message from website",
$message, "From: $email");
header ("Location: ?>

very simple as you can see, but I wont to add $name, $telephone to the email with $message.

Can anybody help me

Lee
 
Just concatenate the two variables into the $message string. I don't know how you want to format the message but if you simply want the variables at the end do this:
Code:
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'] . "\r\n Name: " . $name . "\r\n Telephone: " . $telephone;
Just reverse this if you want that data at the beginning.
 
Code:
$message = "
Form submitted at ".date("d/m/J h:m")."\r\n
By $name\r\n
Phone $telephone\r\n
Message: \r\n $message";
 
sorry to duplicate - didn't see vragabond's post.
 
Thanks for that, I do prefer your suggestion with the date, but with the code below I dont seem to be able to pass the message to the email.

<?
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$email = $_REQUEST['email'];
$message = " Message submitted at ".date("d/m/y h:m")."\r\n
By: $name\r\n
Phone: $telephone\r\n
Message: \r\n $message";
mail("info@hobbsvalve.co.uk", "Message from website",
$message, "From: $email");
header ("Location: ?>

The email comes out like this:

Date: Sun, 05 Mar 2006 16:03:58 +0000
From: multichild@yahoo.co.uk
To: info@hobbsvalve.co.uk
Subject: Message from website All headers

Message submitted at 05/03/06 04:03

By: lee jones

Phone: 01291 421412

Message:


And as you can see all the other information is submitted, except for the message.

Lee
 
hmmm...
put this line in BEFORE the existing line starting $message

Code:
$message = $_REQUEST['message'];
 
I have modified the script further to check for empty fields, and it also stops the page cache'n.

It all works fine again, but the error message doesnt seem to pick up that no text has been inserted into the message field.

It jumps to the error page when any of the other fields are emtpy, but doesnt seem to work for the message field.

As I have used your script to send the feedback to the webmaster, will this create a problem or the empty field check.

All the code is below:

<?
$name = $_REQUEST['name'];
$telephone = $_REQUEST['telephone'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$message = "Message submitted at ".date("d/m/y - h:m")."\r\n
By: $name\r\n
Phone: $telephone\r\n
Message: \r\n $message";
if (!isset($_REQUEST['email'])) {
header ("Location: }
elseif (empty($email) || empty($message) || empty($name)) {
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache");
?>
<html>
<head>
<title>Error</title>
</head>
<body>
<h1>Error</h1>
<p>
Sorry, it appears that you have forgotten to enter either your name, your email address or your message.</p>
<p>Please press the BACK button in your browser and try again.</p>
</body>
</html>
<?
}
else {
mail("rhys@hobbsvalve.co.uk", "Message from website",
$message, "From: $name <$email>");
header ("Location: }
?>

Lee
 
change to
Code:
if (empty($_REQUEST['email']))

the field will always be "set" as it is in a form and is a textbox or similar but may be empty (i.e. blank string)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top