Dear Daniel:
Thanks so much for explaining the code. I'm always afraid to try to replace code when I don't fully get what it is doing. But now I have no choice because, with the next php upgrade on the server, this code will no longer work. Here is the function:
Code:
function replace_email_template_variables($body_text) { // This function replaces the variables in the Body text for the email
global $Today;
global $First_Name;
global $Last_Name;
global $Phone;
global $Email;
global $Age_Group;
global $Flight;
global $Cruise;
global $Credit_Card;
global $Best_Price_Net;
global $Best_Price_Full;
global $New_Pick_Date;
global $N_Pick_Time;
global $Pick_Location;
global $Pick_AP;
global $New_Drop_Date;
global $N_Drop_Time;
global $Drop_Location;
global $Drop_AP;
global $Car_Class;
global $Days_Num;
global $country;
global $employee;
global $Car_Logo;
global $agencyname;
global $Comment;
$Comment = "";
$body_text = eregi_replace('%Today%', $Today, $body_text);
$body_text = eregi_replace('%First_Name%', $First_Name, $body_text);
$body_text = eregi_replace('%Last_Name%', $Last_Name, $body_text);
$body_text = eregi_replace('%Phone%', $Phone, $body_text);
$body_text = eregi_replace('%Email%', $Email, $body_text);
$body_text = eregi_replace('%Age_Group%', $Age_Group, $body_text);
$body_text = eregi_replace('%Flight%', $Flight, $body_text);
$body_text = eregi_replace('%Cruise%', $Cruise, $body_text);
$body_text = eregi_replace('%Credit_Card%', $Credit_Card, $body_text);
$body_text = eregi_replace('%Best_Price_Net%', $Best_Price_Net, $body_text);
$body_text = eregi_replace('%Best_Price_Full%', $Best_Price_Full, $body_text);
$body_text = eregi_replace('%New_Pick_Date%', $New_Pick_Date, $body_text);
$body_text = eregi_replace('%N_Pick_Time%', $N_Pick_Time, $body_text);
$body_text = eregi_replace('%Pick_Location%', $Pick_Location, $body_text);
$body_text = eregi_replace('%Pick_AP%', $Pick_AP, $body_text);
$body_text = eregi_replace('%New_Drop_Date%', $New_Drop_Date, $body_text);
$body_text = eregi_replace('%N_Drop_Time%', $N_Drop_Time, $body_text);
$body_text = eregi_replace('%Drop_Location%', $Drop_Location, $body_text);
$body_text = eregi_replace('%Drop_AP%', $Drop_AP, $body_text);
$body_text = eregi_replace('%Car_Class%', $Car_Class, $body_text);
$body_text = eregi_replace('%Days_Num%', $Days_Num, $body_text);
$body_text = eregi_replace('%country%', $country, $body_text);
$body_text = eregi_replace('%Employee%', $employee, $body_text);
$body_text = eregi_replace('%Car_Logo%', $Car_Logo, $body_text);
$body_text = eregi_replace('%agencyname%', $agencyname, $body_text);
$body_text = eregi_replace('%Comment%', $Comment, $body_text);
return ($body_text);
}
An example of the html template is http://www.carrentalhawaii.com/html/...mation-us.htmlhttp://www.carrentalhawaii.com/html/...mation-us.html
Seems to me the 100 character buffer is not necessary as the email format is handled within the email itself. So is this the right way...?
Code:
$sql = "SELECT * FROM booking WHERE book_id = $book_id ";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query.");
$book = mysql_fetch_array($result);
$body = file_get_contents($html_email_template_file);
str_replace(%First_Name%,$First_Name,%body);
str_replace(%Last_Name%,$Last_Name,%body);
str_replace(%Phone%,$Phone,%body);
etc, doing each possible variable one-by-one. I find mysql_fetch_assoc($result); more compact but am not sure how to use it here. Could I say:
Code:
str_replace(%First_Name%,$book['First_Name'],%body);
or is there a compact way of saying, "Get all the data from the file for that record & replace all the variables in the email with it" using just one statement?
What I am after is a "best practices" model of code I can use whenever I need to get data from a MySQL database, or even from GET & POST variables into an html email. All I have to go on is a very old model of how to do it badly using a method that has been deprecated. I really appreciate your help and skill with the language. It's hard to become fluent in a language when I have to learn it as needed in circumscribed chunks. Mahalo! e
Bookmarks