Jump to content

[SOLVED] function inside foreach loop


php_guest

Recommended Posts

I have a problem because the function inside the following foreach loop stop the looping.

foreach ($emails as $to) {
         list($to,$name) = split(':::',$to,2);
         $message = "testiram nekej";

        send_email ( $subject, $to, $message );
        echo "Mail sent to $name ($to)<br/>\r\n";
}

If I change send_email ( $subject, $to, $message ); with echo "$to" it shows all addresses and not only just the first one from the list as happens if I put function inside the foreach.

 

Why happen that, why it stop? Here is the send_email function:

function send_email ( $subject, $to, $body )
   {
      require ( BASE_PATH . "/lib/phpmailer/class.phpmailer.php" );

      $mail = new PHPMailer();

      //do we use SMTP?
      if ( USE_SMTP ) {
         $mail->IsSMTP();
         $mail->SMTPAuth = true;
         $mail->Host = SMTP_HOST;
         $mail->Port = SMTP_PORT;
         $mail->Password = SMTP_PASS;
         $mail->Username = SMTP_USER;
      }

      $mail->From = ADMIN_EMAIL;
      $mail->FromName = DOMAIN_NAME;
      $mail->AddAddress( $to );
      $mail->AddReplyTo ( ADMIN_EMAIL, DOMAIN_NAME );
      $mail->Subject = $subject;
      $mail->Body = $body;
      $mail->WordWrap = 100;
      $mail->IsHTML ( MAIL_IS_HTML );
      $mail->AltBody  =  html2txt ( $body );

      if ( ! $mail->Send() ) {
         if ( RUN_ON_DEVELOPMENT ) {
            echo $mail->ErrorInfo;//spit that bug out 
         }
         return FALSE;
      }
      else {
         return TRUE;
      }
   } 

Link to comment
https://forums.phpfreaks.com/topic/156636-solved-function-inside-foreach-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.