Solved

Message in Email Not Passing

Posted on 2013-06-25
11
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 83

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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 83

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 57

Accepted Solution

by:
Julian Hansen earned 500 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 83

Expert Comment

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

Open in new window

0
 
LVL 57

Expert Comment

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

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

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!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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