Labeling responses in mail.php

software development

#1

I have a very simple “registration” form that I created in Dreamweaver. I’ve been using a mail.php thingy with it. When I receive the email containing the answers from my form it doesn’t tell me what field they came from. Here’s my php:

<? $to = 'name@somewhere.com'; $subject = 'Registration Form'; $message = 'student name: ' . $_REQUEST['NAME'] . "\n\n" . $_REQUEST['AGE'] . "\n\n" . $_REQUEST['Grade'] . "\n\n" . $_REQUEST['parent'] . "\n\n" . $_REQUEST['PHONE'] . "\n\n" . $_REQUEST['EMAIL'] . "\n\n" . $_REQUEST['address'] . "\n\n" . $_REQUEST['current'] . "\n\n" . $_REQUEST['describe']; $email = $_REQUEST['EMAIL']; $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail ($to, $subject, $message, $headers); header("Location: thanks.html"); ?>

Where it says $message = 'student name: ’ . $_REQUEST[‘NAME’] . “\n\n” I get “student name: john doe”, but the other answers like age and grade just come as numbers and I’d like them to come as “age: 10” or “grade: 1”. Any advice?


#2

You would need to do the same thing as ‘student name:’ . $_REQUEST[‘NAME’] . “\n\n” for each line and label them manually.
All you are doing currently is telling the script to just use the values as the only content.

Change your script to this:
[php]

<? $to = 'name@somewhere.com'; $subject = 'Registration Form'; $message = 'student name: ' . $_REQUEST['NAME'] . "\n\n" "Age: " . $_REQUEST['AGE'] . "\n\n" "Grade: " . $_REQUEST['Grade'] . "\n\n" "Parent: " . $_REQUEST['parent'] . "\n\n" "Phone: " . $_REQUEST['PHONE'] . "\n\n" "E-Mail: " . $_REQUEST['EMAIL'] . "\n\n" "Address: " . $_REQUEST['address'] . "\n\n" "Current: " . $_REQUEST['current'] . "\n\n" "Describe: " . $_REQUEST['describe']; $email = $_REQUEST['EMAIL']; $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail ($to, $subject, $message, $headers); header("Location: thanks.html"); ?>

[/php]


#3

That was the first thing I tried, but it gives me this error message: “Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /homepages/42/d240704714/htdocs/mail.php on line 6”

Just to be sure I’d already tried the exact same thing, I copied your script and got the same message.


#4

If noone replies back in the next couple of hours I’ll have a crack at it - I’m away from my desk today so when I get back I’ll use somoe proper tools to create the script.


#5

[quote]That was the first thing I tried, but it gives me this error message: “Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /homepages/42/d240704714/htdocs/mail.php on line 6”
[/quote]

Are you sure you’re on DreamHost? That error message sounds distinctly like you’re hosted somewhere else.


#6

Oh. Well actually I have no idea what Dreamhost is. I found this site on google. I’m very lost.


#7

Well…Dreamhost is a Web Host and domain registrar.
This is the support / general discusion forum for it’s members and other folks just visiting.

I wasn’t able to get to my desk last night, but I think I know where I made a nooby mistake.
Each of those lines needs a . in front of them such as you had before.

If you are looking for a forum dedicated to coding, then I would recommend DreamInCode, they have sections dedicated to almost every programming language out there, ans should be more than helpful :slight_smile:


#8

This should work, it’s not tested though.

[php]<?php

$to = ‘name@somewhere.com’;
$subject = ‘Registration Form’;
$message = 'student name: ’ . $_REQUEST[‘NAME’] . “\n\n”

. "Age: " . $_REQUEST[‘AGE’] . “\n\n”
. "Grade: " . $_REQUEST[‘Grade’] . “\n\n”
. "Parent: " . $_REQUEST[‘parent’] . “\n\n”
. "Phone: " . $_REQUEST[‘PHONE’] . “\n\n”
. "E-Mail: " . $_REQUEST[‘EMAIL’] . “\n\n”
. "Address: " . $_REQUEST[‘address’] . “\n\n”
. "Current: " . $_REQUEST[‘current’] . “\n\n”
. "Describe: " . $_REQUEST[‘describe’];

$email = $_REQUEST[‘EMAIL’];
$headers = 'From: ’ . $email . “\r\n” .
'Reply-To: ’ . $email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();

mail ($to, $subject, $message, $headers);
header(“Location: thanks.html”);
?>[/php]