• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Need PHP Variable to be added to Subject in HTML EMAIL

This should be simple for a PHP Expert. I need to have the PHP Variable $BuyerSpecialist  added to the email subject when the form is sent.

This is what I currently have but I was just guessing. The only thing that comes through is the Showing Request -
$Subject = "Showing Request - " .$BuyerSpecialist ."" ;

Link to webpage
http://bit.ly/9S2a3h

Below is the php code
<?php
$recipients = array(

'recipient_1' => 'blah@blahblah, blah@blahblah',
'recipient_2' => 'blah@blahblah, blah@blahblah',

);


// get posted data into local variables
$EmailFrom = "helen@helenoliveri.com";
$EmailTo = $recipients[$_REQUEST['recipient']];
$Subject = "Showing Request - " .$BuyerSpecialist ."" ;
$BuyerSpecialist = Trim(stripslashes($_POST['BuyerSpecialist'])); 
$Date = Trim(stripslashes($_POST['Date'])); 
$TimeFrame = Trim(stripslashes($_POST['TimeFrame'])); 
$Number = Trim(stripslashes($_POST['Number'])); 

$row=<<<ROW

	<tr style='margin-top:.5em; '><td colspan='4'><font size='+1'><b>Showing TOKEN1</b></font></td></tr>
	<tr><td><font size='+1'><b>Address</b></font></td> <td><font size='+1'><b>City</b></font></td> <td><font size='+1'><b>MLS#</b></font></td> <td><font size='+1'><b>Time</b></font></td></tr>
	<tr><td><font size='+1'>TOKEN2</font></td> <td><font size='+1'>TOKEN3</font></td> <td><font size='+1'>TOKEN4</font></td> <td><font size='+1'>TOKEN5</font></td></tr>

ROW;

$msg="";
foreach($_POST['Address'] as $k=>$v)
{
	$tmp=$row;
	$tmp=str_replace('TOKEN1', (1 + (int)$k), $tmp);
	$tmp=str_replace('TOKEN2', !empty($_POST['Address'][$k]) ? stripslashes(trim($_POST['Address'][$k])) : "&nbsp;",$tmp);	
	$tmp=str_replace('TOKEN3', !empty($_POST['City'][$k]) ? stripslashes(trim($_POST['City'][$k])) : "&nbsp;",$tmp);	
	$tmp=str_replace('TOKEN4', !empty($_POST['MLS'][$k]) ? stripslashes(trim($_POST['MLS'][$k])) : "&nbsp;",$tmp);	
	$tmp=str_replace('TOKEN5', !empty($_POST['Time'][$k]) ? stripslashes(trim($_POST['Time'][$k])) : "&nbsp;",$tmp);
	$msg.=$tmp;
}


// Comments

$Notes = Trim(stripslashes($_POST['Notes'])); 




// validation
$validationOK=true;
if (Trim($BuyerSpecialist)=="") $validationOK=false;
if (Trim($Date)=="") $validationOK=false;
if (Trim($TimeFrame)=="") $validationOK=false;
if (Trim($Number)=="") $validationOK=false;
/*
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.helenoliveri.com/pages/showing.html\">";
  exit;
}
*/

// prepare email body text
$Body = "";
$Body .= "<font size='+1'>BuyerSpecialist: </font>";
$Body .= "<font size='+1'>". $BuyerSpecialist ."</font>";
$Body .= "<br>";
$Body .= "<br>";
$Body .= "<font size='+1'>Date: </font>";
$Body .= "<font size='+1'>".$Date ."</font>";
$Body .= "<br>";
$Body .= "<br>";
$Body .= "<font size='+1'>TimeFrame: </font>";
$Body .= "<font size='+1'>".$TimeFrame ."</font>";
$Body .= "<br>";
$Body .= "<br>";
$Body .= "<font size='+1'>Number: </font>";
$Body .= "<font size='+1'>".$Number ."</font>";
$Body .= "<br>";
$Body .= "<br>";
$Body .= "<table border='1' cellpadding='1'>" .$msg . "</table>";
$Body .= "<br>";
$Body .= "<font size='+1'>Notes: </font>";
$Body .= "<font size='+1'>".$Notes ."</font>";
$Body .= "<br>";


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: <$EmailFrom>\r\n";
//echo $Body;exit;


// send email 
$success = mail($EmailTo, $Subject, $Body, $headers);

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.helenoliveri.com/pages/showing.html\">";
}
else{
  print "error";
}
?>

Open in new window

0
shawnzer
Asked:
shawnzer
3 Solutions
 
hawardenCommented:
Try: $Subject = "Showing Request - $BuyerSpecialist" ;

Your syntax was for function calls.
0
 
thedwillCommented:
$Subject = "Showing Request - " .$BuyerSpecialist ;


too many quotes!  . concats your quoted text with you variable, so the above should yield:

Showing Request - VALUE of Buyer Specialist

0
 
hieloCommented:
>>This is what I currently have but I was just guessing.
>>$Subject = "Showing Request - " .$BuyerSpecialist ."" ;
You guessed CORRECTLY!!! BUT you need to set the value of $Subject AFTER you have set the value of $BuyerSpecialist. In other words, swap the order of lines 13 and 14:
...
// get posted data into local variables
$EmailFrom = "helen@helenoliveri.com";
$EmailTo = $recipients[$_REQUEST['recipient']];
$BuyerSpecialist = Trim(stripslashes($_POST['BuyerSpecialist'])); 
$Subject = "Showing Request - " .$BuyerSpecialist;
$Date = Trim(stripslashes($_POST['Date'])); 
$TimeFrame = Trim(stripslashes($_POST['TimeFrame'])); 
$Number = Trim(stripslashes($_POST['Number'])); 

...

Open in new window

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
shawnzerAuthor Commented:
Try: $Subject = "Showing Request - $BuyerSpecialist" ;

Did not work but $BuyerSpecialist did not show in the subject line either just the

Showing Request -
0
 
hawardenCommented:
Shawzer, as hielo pointed out, you are assigning the value to $BuyerSpecialist ~after~ trying to use it in $Subject, so naturally there is nothing in it. You need to assign the value first, and then use it in $Subject:

$BuyerSpecialist = Trim(stripslashes($_POST['BuyerSpecialist']));
$Subject = "Showing Request - $BuyerSpecialist" ;
0
 
shawnzerAuthor Commented:
Thanks again hielo !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now