Solved

Message in Email Not Passing

Posted on 2013-06-25
11
149 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 82

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
 

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 82

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 51

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 82

Expert Comment

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

Open in new window

0
 
LVL 51

Expert Comment

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now