title: PHP replace token in html email variable before sending
body: <p>I have an email that I send out to subscribers of my site. I do this by getting the subscriber list from my database and the looping through the array and sending one email at a time... I know there is a way to send all at once but this is why I do it this way and the bit I need help with...</p>
  
  <p>The HTML email contains 2 tokens:</p>
  
  <p><code>{name}</code> and <code>{date}</code></p>
  
  <p>What i need to do is insert the date in the HTML email replacing the <code>{date}</code> token and insert the name replacing the <code>{name}</code> for each email send (as the name is always different).</p>
  
  <p>This is what I have:</p>
  
  <pre><code>        $result = $wpdb-&gt;get_results( "SELECT * FROM wp_newsletter WHERE `id` IN ( $userIds )");
          for($i = 0, $size = sizeof($result); $i &lt; $size; ++$i){
            add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
            $to .= $result[$i]-&gt;name.'&lt;'.$result[$i]-&gt;email.'&gt;';
            $mail = wp_mail( $to, $subject , $message, $headers);
          }
  </code></pre>
  
  <p>as you can see above I have two variables from the database:</p>
  
  <p><code>$result[$i]-&gt;name</code></p>
  
  <p><code>$result[$i]-&gt;email</code></p>
  
  <p>and <code>$message</code> is the HTML email body that has the 2 tokens that needs to be replaced.</p>
  
  <p>so.... everything is working as expected for the looping and sending I just need some help with how I do the token replace for <code>{name}</code> and <code>{date}</code>.</p>
  
  <p>Any help with this will be very much appreciated.</p>