Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Message in Email Not Passing

Posted on 2013-06-25
11
Medium Priority
?
167 Views
Last Modified: 2013-06-26
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

0
Comment
Question by:DS928
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39276784
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

0
 

Author Comment

by:DS928
ID: 39276824
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?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39276837
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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DS928
ID: 39276845
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.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39276895
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

0
 

Author Comment

by:DS928
ID: 39276909
Still Labels.  Not quit sure why these values aren't passing.  Should some variable names be changed?
0
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 39277080
Change
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

TO
$row=mysql_fetch_array($sql);
if ($row) {
	$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']; // Is this posted 
 	$subject = "Menuhead.com";
	$message="Name:  $RestName\n";
        $message += "Emai: $Email \n";
 	$headers = "From: <info@menuhead.com Menuhead";
 	mail($to,$subject,$message,$headers);
 	echo "Mail Sent.";
}
else {
 // process error here
}

Open in new window

Your original code reads from the database and then spins its wheels setting values that are overwritten if there is more than one record - which their most likely won't be because you are filtering by an ID. But in the second section some of those values are overwritten by POST values - which does not make sense. In the context of your earlier question where you were only POSTING the LiD not sure where the ESend is comming in unless something changed.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39277091
Don't you mean...
$message .= "Email: $Email \n";

Open in new window

0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 39277191
um (blush) yes - was in JScript mode with my project ...
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39277262
I understand that!
0
 

Author Closing Comment

by:DS928
ID: 39278368
Bingo! That worked!  Thank you!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question