Solved

Message in Email Not Passing

Posted on 2013-06-25
11
158 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 58

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 58

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

626 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