PHP email - moving a field from the 'from' field into the body of the email when it is received

Hi
I have a php email form that sends emails to multiple addresses depending on the dropdown field selected. I've had some great help on this forum for getting the form working but still have a problem with the php.

This is the section of code:

mail($dept, "Housekeeping Query", $question, "From: $email $name");

I want the email to arrive in the inbox as follows:

From field: senders email address
Subject heading: Housekeeping Query

Body of the email: name of person sending from the name field on the form, email address of the person sending, contents of the text box from the form.

At the moment with mail($dept, "Housekeeping Query", $question, "From: $email $name"); I have the name of the person sending in the from field of the email with their email address ( ie: myemail@myemailaddress.com.joe.bloggs ) It works, but the end user wants the name of the sender in the body of the email. Has anyone got any ideas on how I could do this? Thanks in advance!
html: 
<form action="house_keeping.php" method="post">
<div align="center">
<table border="0" cellpadding="8" cellspacing="8"
	summary="feedback form">
	<tr>
		<td>
		<div align="left"><font size="2" class="bodys">Your Name:</font></div>
		</td>
		<td>
		<div align="left"><input type="text" name="name" size="25" /></div>
		</td>
	</tr>
	<tr>
		<td>
		<div align="left"><font size="2" class="bodys">Email address:</font></div>
		</td>
		<td>
		<div align="left"><input type="text" name="email" size="25" /></div>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<p align="left"><font size="2" class="bodys">Question or Request:</font><font
			size="1"><br />
		</font> <textarea rows="8" cols="40" name="comments"></textarea></p>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<div align="left">Which area does your query come under? 
		  &nbsp;&nbsp;<select name="dept">
			<option value="myemail1@myemailaddress.com">Logistics</option>
			<option value="myemail2@myemailaddress.com">HPI Queries</option>
			<option value="myemail3@myemailaddress.com">V5 Queries</option>
		</select></div>
		</td>
	</tr>
	<tr>
		<td align="center" colspan="2">
		<div align="left"><input type="submit" value="Send " /> <br />
		</div>
		</td>
	</tr>
</table>
</div>
</form>
 
php:
 
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$question = $_POST["comments"];
$dept = $_POST["dept"];
 
 
mail($dept, "Housekeeping Query", $question, "From: $email $name");
 
 
?>

Open in new window

GizmoPigAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NicoJuicyCommented:
I thinks this would help.

mail($dept, "Housekeeping Query", $question, "From: $email $name");

If i recall right, your body is in the 3rd field (so it's $question).

You can add combine more text with the        .      in php.

Eg.
mail($dept, "Housekeeping Query", $question . "From: " . $email $name, "From: $email $name");

Is this what you want?
0
BrianMMCommented:
just append it...

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$dept = $_POST["dept"];
$query = $_POST["comments"];
$query .= "\n\nSender: ".$name." (".$email.")";
 
mail($dept, "Housekeeping Query", $query, "From: $email $name");
  ?>

You can do what you want really... if your sending it as HTML change the \n to <br>...

Btw, \n will add a carriage return, \t will indent... if yout sending plain text and want to format it slightly...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alien13Commented:
Hi,

I have an attached code that should do what you want. It will send it in the following format:
Name Email
Question

Hope this helps, if you need anything else, just say so.
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$question = $_POST["name"] . " " . $_POST["email"] . "\n" . $_POST["comments"];
$dept = $_POST["dept"];
 
mail($dept, "Housekeeping Query", $question, "From: $email $name");
 
 
?>

Open in new window

0
GizmoPigAuthor Commented:
Thanks all 3 of you - I could only get BrianMM's to work for me though and it did exactly what I wanted, adding a sender: senders name (sender's email) line to the bottom of the text of the email. Thanks for the extra info on the  
 \n and \t tags as well - that'll come in handy as I am still new to php coding!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.