1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

An exception occurred: Cannot send headers; headers already sent in

Discussion in 'XenForo Development Discussions' started by AndyB, Apr 2, 2014.

  1. AndyB

    AndyB Well-Known Member

    In my add-on Inactive Members, I would like to display in the browser the username of the email being sent. Currently if 1000 emails are sent, the browser sits there without any confirmation until it's done.

    This is an example of my test code that runs just once, but will echo 1~100 to let me know it's working.

    // get visitor data
    $visitor XenForo_Visitor::getInstance();

    // username
    $username $visitor['username'];

    // email
    $email $visitor['email'];

    // define user variable
    $user = array(
    'username' => $username,
    'email' => $email

    // prepare mailParams                  
    $mailParams = array(
    'user' => $user,
    'subject' => $subject,
    'message' => $message
    // prepare mail variable
    $mail XenForo_Mail::create('inactivemembers_contact'$mailParams);

    // send mail to queue
    $mail->queue($user['email'], $user['username']);

    $count 100;

    for (
    $i '<br />';
    This echo's 1 through 100 just fine, but after that instead of returning this error message is displayed:

    An exception occurred: Cannot send headers; headers already sent in /home/southbay/www/forums/library/Andy/InactiveMembers/ControllerPublic/InactiveMembers.php, line 397 in /home/southbay/www/forums/library/Zend/Controller/Response/Abstract.php on line 321
        Zend_Controller_Response_Abstract->canSendHeaders() in Zend/Controller/Response/Abstract.php at line 115
        Zend_Controller_Response_Abstract->setHeader() in XenForo/ViewRenderer/Abstract.php at line 63
        XenForo_ViewRenderer_Abstract->__construct() in XenForo/ViewRenderer/HtmlPublic.php at line 18
        XenForo_ViewRenderer_HtmlPublic->__construct() in XenForo/Dependencies/Public.php at line 212
        XenForo_Dependencies_Public->getViewRenderer() in XenForo/FrontController.php at line 537
        XenForo_FrontController->_getViewRenderer() in XenForo/FrontController.php at line 141
        XenForo_FrontController->run() in /home/southbay/www/forums/index.php at line 13
    Does anyone know how I can properly echo something to the browser so the admin knows the emails are being sent.

    Thank you.
  2. AndyB

    AndyB Well-Known Member

    I resolved this by putting an exit() after the for loop. I've included a phrase telling the user to press the back button to return.

Share This Page