The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Problem Inserting Variables into Posted Text String

Hello All --

I have a problem with an email script I'm trying to implement. The script reads in a delimited txt file, runs it through an array, inserts values from the file such as name, date, card number into the email text and send the email to each email address read in from the text file. This code works quite well as is:

My problem is I do not want to build the message here. I want to give my users the ability to build the email themselves in a form that posts to this page AND determine where the person's name, expiration date and other dynamic info appear in the message. I have javascript buttons on this form that allow them to do this - and it inserts the PHP code equivalent of the variables I use on the mailing portion.

However, when I post the message through, it is one complete string and does not interpret my variables. I have split the string into an array and reassembled it as another string using something similar to this:

$sMessage = str_replace(array_keys($aReplacements), $aReplacements, 'This is a message to {{RECIPIENT}} with the subject "{{SUBJECT}}".');echo $sMessage; #This is a message to you@youraddress.com with the subject "A brief message from our sponsor.".?>

$sMessage = str_replace(array_keys($aReplacements), $aReplacements, 'This is a message to {{RECIPIENT}} with the subject "{{SUBJECT}}".');echo $sMessage; #This is a message to you@youraddress.com with the subject "A brief message from our sponsor.".?>