php_guest Posted May 3, 2009 Share Posted May 3, 2009 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 More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 Can you post what var_dump($to); prints out? Link to comment https://forums.phpfreaks.com/topic/156636-solved-function-inside-foreach-loop/#findComment-824788 Share on other sites More sharing options...
php_guest Posted May 3, 2009 Author Share Posted May 3, 2009 it wrote string(22). Link to comment https://forums.phpfreaks.com/topic/156636-solved-function-inside-foreach-loop/#findComment-824802 Share on other sites More sharing options...
Mark Baker Posted May 3, 2009 Share Posted May 3, 2009 try changing the require in the send_email() function to require_once Link to comment https://forums.phpfreaks.com/topic/156636-solved-function-inside-foreach-loop/#findComment-824813 Share on other sites More sharing options...
php_guest Posted May 3, 2009 Author Share Posted May 3, 2009 Mark tnx!, it works! Link to comment https://forums.phpfreaks.com/topic/156636-solved-function-inside-foreach-loop/#findComment-824817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.