My question is basically whether or not what I am trying to do is even possible. I am either doing something incorrectly, or I am dreaming too big... (Insert unprofessional php designer disclaimer here).
I am creating an automatic emailing system. I have the layout of my email stored in a text file. Information that I wanted to be written dynamically is represented by what I am calling tags (i.e. [DATE], [CUSTNAME], [MESSAGE]...).
When an email is created and delivered, variables are passed to a function from my index page, I simply include the text file while replacing my tags with dynamic content. This works beautifully for me, up until I wanted to beef up content in the newsletter. Now I want to add in a section that is called from an independent function. This caused my Email function to actually display the content from the called function 3 times right there rather than complete the function of shooting the email and redirect as necessary.
My code (contained inside a function) before updating (working for me):
$EmailBodyTEXT = addslashes($EmailBody);
$EmailBody =
str_replace('[YEAR]', date(Y),
str_replace('[SUBJECT]', $EmailSubject,
str_replace('[DATE]', date('l, F j, Y'),
str_replace('[MESSAGE]', $EmailBody, file_get_contents($url . 'newsletter_BLANK.txt')))));
My code after updating (fail):
$EmailBodyTEXT = addslashes($EmailBody);
$EmailBody =
str_replace('[YEAR]', date(Y),
str_replace('[SUBJECT]', $EmailSubject,
str_replace('[DATE]', date('l, F j, Y'),
str_replace('[MESSAGE]', $EmailBody,
str_replace('[PHOTOSTREAM]', PhotoStream(CUST), file_get_contents($url . 'newsletter_BLANK.txt'))))));
For what it is worth, I tried to 'load' the second function in a $variable and replaced the function call with the variable, exact same result, as I anticipated.
How should I call this function to not 'execute' on the spot, but continue with the process of the containing function, which would pass this content into the email in the process of creation and delivery? Am I simply incorrect in thinking there is a way to load a function from the str_replace process? Is there a more obvious way of trying to do this (basically a mail merge) function?
Please let me know your thoughts and if more code is needed from me.
Here is the PhotoStream():
function PhotoStream($DispTo) {
global $url, $uri, $urp, $locurl;
if(empty($DispTo)) { echo 'unconfigured'; continue; } else {
if($DispTo == 'CUST') { $DispTo = urlencode('$redacted'); } else { $DispTo = '$redacted'; }
}
if($getPics = mysql_query("SELECT pid, px, title FROM photos ORDER BY pubdate DESC LIMIT 6")) {
echo '<fieldset><div id="wrapNL">';
while($gPics = mysql_fetch_array($getPics)) {
$pid = $gPics{'pid'};
$pex = $gPics{'px'};
$ptl = $gPics{'title'};
echo '<div id="pthumbs"><a href="' . $uri . $DispTo . '&PID=' . $pid . $locurl . '">';
echo '<img src="' . $urp . 'uploads/' . $pid . '.' . $pex . '" alt="' . $ptl . '" title="' . $ptl . '">';
echo '</a></div>';
}
echo '</div></fieldset>';
}
}