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:


$filestring = file_get_contents ('renewcards.txt');
$trimstring = trim ($filestring);

$linearray = explode ("\n", $trimstring);

$headers['Subject'] = 'Ann Arbor District Library card renewal';

foreach ($linearray as $mailarray)
  $line = explode ("|", $mailarray);
  $exdatetrimmed = trim ($line [1]);
  $card = trim ($line [2]);
  $name = trim ($line [3]);

  $message = "Name: ".$name."\nCard: ".$card."\n\nYour
  library card from the xxx
  Library\r\nis due for renewal on ".$exdatetrimmed.".
  Please bring your \r\ncurrent picture I.D. and proof of
  address to the Circulation\r\nDesk at any xxx location
   \r\nto renew your card. ";

  $headers['To'] = $line[0];
  $recipients = $line [0];
  //$mail_object =& Mail::factory ("mail", $params);
  //$mail_object -> send($recipients, $headers, $message);

if (mail($recipients, $subject, $message)) {
echo ("Message Sent");
} else {
echo "Message Delivery Failed.";

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:

if (isset($postedmessage)) 
$message_pieces = array(); // array to store each 
if (is_int(strpos('"', $postedmessage))) 
$message_pieces = explode('"', $postedmessage); // Multiple 
} else { 
$message_pieces[] = $postedmessage; // Just one 

 foreach ($message_pieces as $returned_message) {
$message_to_send = $message_to_send.$returned_message." ";
The result of this, of course, is another string.

So, I'm wondering, how I can rebuild this posted string and have my variables display correctly?

Thanks in advance for any help you can provide.