title: Fatal error: Call to undefined method stdClass::AddAddress() in PHP mailer
body: <p>I'm trying to send an e-mail to multiple e-mail address in my database. Here is my current code.I need to have them query my database and send the e-mail to each e-mail address.It is  working but email was send to the first e-mail address only, and got an error "Fatal error: Call to undefined method stdClass::AddAddress()".Where am I going wrong here?</p>
  
  <pre><code>&lt;?php
  $elist = $database-&gt;getRows("SELECT * FROM `emails`");
  
  foreach($elist as $emails){
          $frm = 'test@gmail.com';
          $sub = 'Weekly Work Report';
          ob_start();
          include_once('mail_content.php');
          $mail_body = ob_get_contents(); 
          ob_end_clean();
          $to = $emails['email'];
          $mailstatus = lm_mail('1', '2', $to, '3', $frm, 'HR', $sub, $mail_body);
  if ($mailstatus == 'ok') {
  $response-&gt;redirect('index.php?com_route=user_report');
  } else {
      echo $mailstatus;
  }
  }
  ?&gt;
  
  function lm_mail($head_mid='',$head_mname='',$to_mid ,$to_mname='',$reply_mid,$reply_mname='',$subject,$body,$attachments='')
  {
  
      include_once 'phpmailer/mail_config.php';
      if(SMTP_mail)
      {
          // Send SMTP Mails
          $mail-&gt;From =$head_mid ;  // From  Mail id
          $mail-&gt;FromName = $head_mname; // From  Name
  
          $mail-&gt;AddAddress($to_mid,$to_mname); // To Address
          $mail-&gt;AddReplyTo($reply_mid,$reply_mname); // From Address
  
          $mail-&gt;Subject=$subject;
  
          $mail-&gt;Body =  $mail_body.$body; //HTML Body
          $mail-&gt;AltBody = "This is the body when user views in plain text format"; //Text Body
  
          if(!$mail-&gt;Send())
          {
              return $mail-&gt;ErrorInfo;
          }
          else
          {
             return 'ok';
          }
      }
      else
      {
          $mail  = new PHPMailer(); // defaults to using php "mail()"
          $mail-&gt;AddReplyTo($reply_mid,$reply_mname); // Sender address
          $mail-&gt;AddReplyTo($reply_mid,$reply_mname); // replay to address
  
          $address = $to_mid;  // to addtesas
          $mail-&gt;AddAddress($address, $to_mname);
  
          $mail-&gt;Subject    = $subject;
          $mail-&gt;AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  
          $mail-&gt;MsgHTML($mail_body.$body);
          if(!$mail-&gt;Send())
          {
              return  $mail-&gt;ErrorInfo;
          }
          else { return  'ok'; }
      }
  }
  </code></pre>