title: Two versions of same email to two different recipients using class.phpmailer.php
body: <p>I'm trying to send two versions of the same email to two recipients using phpMailer</p>
  
  <p>Depending on the email I need to send one version or another.</p>
  
  <p>At the moment I'm able to send only the same version to both email address</p>
  
  <pre><code>&lt;?php               
  require_once('class.phpmailer.php');
  if(isset($_POST['Submit'])) {
  $fname = $_POST['fname'];
  $maileremail = $_POST['maileremail'];
  $subject = $_POST['subject']; 
  $message = $_POST['message']; 
  
  $mail = new PHPMailer();
  
  $text = 'The person that contacted you is  '.$fname.'  E-mail: '.$maileremail.' Subject: '.$subject.' Message: '.$message.' :';
  $body = eregi_replace("[\]",'',$text);
  
  $text2 = 'The person that contacted you is  '.$fname.'  E-mail: REMOVED - To get email address you must login Subject: '.$subject.' Message: '.$message.' :';
  $body2 = eregi_replace("[\]",'',$text2);
  
  $mail-&gt;IsSMTP(); // telling the class to use SMTP
  $mail-&gt;Host = "xxxxx.xxxxx.xxx"; // SMTP server
  $mail-&gt;SMTPAuth = true;                  // enable SMTP authentication
  $mail-&gt;SMTPKeepAlive = true;                  // SMTP connection will not close after each email sent
  $mail-&gt;Host = "xxxxx.xxxxx.xxx"; // sets the SMTP server
  $mail-&gt;Port = XXXXXXXX;                    // set the SMTP port for the GMAIL server
  $mail-&gt;Username = "xxxxx@xxxxx.xxx"; // SMTP account username
  $mail-&gt;Password = "XXXXXXXX";        // SMTP account password
  $mail-&gt;SetFrom('xxxxx@xxxxx.xxx', 'XXXXXXXX');
  $mail-&gt;Subject = $subject;
  
  $add = array("first@email.xxx", "second@email.xxx");
  
  foreach($add as $address) { 
      if($address == "first@email.xxx") {
          $mail-&gt;AddAddress($address, "xxxxxxxxx"); 
          $mail-&gt;Body = $body;
      }
      elseif($address == "second@email.xxx") {
          $mail-&gt;AddAddress($address, "xxxxxxxxx"); 
          $mail-&gt;Body = $body2;
      }                       
  }
  
  if(!$mail-&gt;Send()) {
       echo "Mailer Error: " . $mail-&gt;ErrorInfo;
  } else {
       echo "&lt;h3&gt;&lt;b&gt;Message sent!&lt;/b&gt;&lt;/h3&gt;";
  }}?&gt;
  </code></pre>