Link to home
Start Free TrialLog in
Avatar of DS928
DS928Flag for United States of America

asked on

Message in Email Not Passing

I have a form that sends E'mails.  This works fine.  The problem is that I can't getthe message portion to show.

<?php
include("config.php");
$Lid = $_POST['Lid'];
$Lid = mysql_real_escape_string($Lid);  
mysql_query("SET CHARACTER SET utf8");
$sql=mysql_query("SELECT tblRestaurants.RestName,tblLocations.StreetNumber,tblLocations.Street,
	tblLocations.CrossOne, tblLocations.CrossTwo, tblCities.CityName,tblStates.StateName,tblZipCodes.ZipCodeName,
	tblLocations.Phone,tblLocations.Email, tblLocations.Fax, tblLocations.SMS, tblLocations.LocationID
	FROM tblLocations
	INNER JOIN tblRestaurants ON tblRestaurants.RestID = tblLocations.RestID
	INNER JOIN tblCities ON tblCities.CityID = tblLocations.CityID
	INNER JOIN tblStates ON tblStates.StateID = tblLocations.StateID
	INNER JOIN tblZipCodes ON tblZipCodes.ZipCodeID = tblLocations.ZipCodeID
	WHERE tblLocations.LocationID = '$Lid'");
	while($row=mysql_fetch_array($sql))
	{
	$RestName = $row['RestName'];
	$StreetNumber = $row['StreetNumber'];
	$Street = $row['Street'];
	$CrossOne = $row['CrossOne'];
	$CrossTwo = $row['CrossTwo'];
	$City = $row['CityName'];
	$State = $row['StateName'];
	$ZipCode = $row['ZipCodeName'];
	$Phone = $row['Phone'];
	$Email = $row['Email'];
	$Fax = $row['Fax'];
	$SMS = $row['SMS'];
	$Lid = $row['LocationID'];
	}
 
    $to = $_POST['ESend'];
 	$subject = "Menuhead.com";
 	$RestName = $_POST['RestName'];
	$Email = $_POST['Email'];
	$message="
	Name: " . $_POST['RestName']." \n
	Emai: $Email \n";
 	$from = "Menuhead";
 	$headers = "From:" . $from;
 	mail($to,$subject,$message,$headers);
 	echo "Mail Sent.";
 ?>

Open in new window

Avatar of Gary
Gary
Flag of Ireland image

Not sure what you are trying to do here
	$message="
	Name: " . $_POST['RestName']." \n
	Emai: $Email \n";

Open in new window

But try
$message='Name: "' . $_POST['RestName'].'" \nEmail: $Email \n';

Open in new window

Avatar of DS928

ASKER

Not quite.  I should be getting back:

Name: Name of Restaurant
Email: Email of Restaurant

What I am getting is.

Name:''\nEmail:$Email\n

Is there a way to check if the first part is grabbing the values?
First, if you are letting users put in the 'To:' email address, you are inviting them to spam the world.  You don't appear to be doing any filtering or checking of your inputs either.

Other than that... try this.
 	$RestName = $_POST['RestName'];
	$Email = $_POST['Email'];
	$message="Name: $RestName\r\n Email: $Email \r\n";
 

Open in new window

Avatar of DS928

ASKER

All that comes back are the labels.

Name:
Email:

I know the values are there because I did an echo on the above PHP query and all of the values appeared.  This is just very basic for now, once this works I can go onto the next step.
I'm wondering if you are confusing a form POST with 'rows' from the database because you are using the same variable names in two different ways.  Try this..
 	//$RestName = $_POST['RestName'];
	//$Email = $_POST['Email'];
	$message="Name: $RestName\r\n Email: $Email \r\n";
 

Open in new window

Avatar of DS928

ASKER

Still Labels.  Not quit sure why these values aren't passing.  Should some variable names be changed?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Don't you mean...
$message .= "Email: $Email \n";

Open in new window

um (blush) yes - was in JScript mode with my project ...
I understand that!
Avatar of DS928

ASKER

Bingo! That worked!  Thank you!