My challenge here, is to describe my problem clearly.
I have a peculiar problem, at least for me.
I want to hold a variable name (Ex. $issue_num) in a table field. I then want to put that variable name in the body of an email message, while at the same time, extracting data from a separate database that is connected to that variable.
Example... Table one contains a field name "email_template_1_body". The contents of that table is a sentence that contains a variable name....
Your issue # is $issue_num
So, I use a database connection to extract that info from table 1 and I end up with a variable called "$theemail_template_1_body". Basically, it contains this...
$theemail_template_1_body = "Your issue # is $issue_num";
I then run a database command to extract the value of $issue_num from a separate database table field. For example, that data is equal to this...
$issue_num = "32234"
However, when I insert the variable "$theemail_template_1_body" into a mail command, it does not insert the results of $issue_num, it prints the name of the variable "$issue_num". So, the customer receives an email that looks something like this.
Hello James,
Your issue has been assigned. Your issue # is $issue_num .
Here is my code....
<?
// Page Name: database_connect_1.php
// This page connects to a database table that contains a field ($email_template_1_body) which contains some text and a variable named "$issue_num".
// OPEN DATABASE CONNECTION AND RETRIEVE INFO FROM TABLE "email_template_1"
$DBhost = "localhost";
$DBuser = "dbusername";
$DBpass = "dbpassword";
$DBName = "thedbname";
// TABLE NAME TO ACCESS
$table = "email_template_1";
mysql_connect($DBhost,$DBuser,$DBpass) or die("$db_connect_failed");
@mysql_select_db("$DBName") or die("$db_select _failed $DBName in page (email-temp-1.php)");
{
$sqlquery = "SELECT * FROM $table";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result); $i = 0;
/* If Nothing, print this */
if ($number < 1) {
print "<div><center><font face='verdana' size='2' color='blue'><b>No data found.</b></font></center>
</div>";
}
/* options database variables */
else {
while ($number > $i) {
$theemail_template_1_subject = mysql_result($result,$i,"email_template_1_subject");
$theemail_template_1_body = mysql_result($result,$i,"email_template_1_body");
$theemail_template_1_defaultbody = mysql_result($result,$i,"email_template_1_defaultbody");
$theemail_template_1_defaultsubject = mysql_result($result,$i,"email_template_1_defaultsubject");
$theemail_template_1_usedefault = mysql_result($result,$i,"email_template_1_usedefault");
$theemail_template_1_print1s = mysql_result($result,$i,"email_template_1_print1");
$theemail_template_1_print2 = mysql_result($result,$i,"email_template_1_print2");
$i++;
}
}
}
// ----------------------- If USE DEFAULT is chosen, do this ---------------
if($theemail_template_1_usedefault == "Yes"){
$theemail_template_1_subject = $theemail_template_1_defaultsubject;
$theemail_template_1_body = $theemail_template_1_defaultbody;
}
// ---------------------------------------------------------------------------
// BE POLITE -- CLOSING DATABASE CONNECTION
MYSQL_CLOSE();
?>
Here is the page that calls the page above and sends an email that should contain the info contained in the variable.
<?
// INCLUDE THE DATA FROM EMAIL_TEMPLATE_1 DATABASE TABLE
// This include connects to the page listed above in this post.
include("database_connect_1.php");
// The following include page has code that connects to a database table and
// extracts the issue # from a table field called "issue_num".
include("database_issue_numbers.php");
// Now, I want to send an email that contains the field
// $theemail_template_1_body which I wish also contains another data variable
// name ($issue_num).
mail("$theEmail", "$theemail_template_1_subject | Sub: $Subject", "
Hi $Name,
$theemail_template_1_body
\n", "From: $theSupportEmail");
}
?>
The resulting email looks something like this.
Hi James,
Your issue # is $issue_num
It should look like..
Hi James,
Your issue # is 33242