title: "An error occurred while handling another error: yii\web\HeadersAlreadySentException"
body: <p>I am trying to submit a comment on a guestbook application based on the Yii 2 Framework. On localhost on my PC works everything fine, but on the shared hosting when I want to submit a comment in View, I get this error.</p>
  <p>Here is the error:</p>
  <pre class="lang-none prettyprint-override"><code>An error occurred while handling another error:
      exception 'yii\web\HeadersAlreadySentException' with message 'Headers already sent in /home/mahdikas/public_html/guestbook/controllers/PostController.php on line 117.' in /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/web/Response.php:366
      Stack trace:
      #0 /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response-&gt;sendHeaders()
      #1 /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/web/ErrorHandler.php(135): yii\web\Response-&gt;send()
      #2 /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler-&gt;renderException(Object(yii\web\HeadersAlreadySentException))
      #3 [internal function]: yii\base\ErrorHandler-&gt;handleException(Object(yii\web\HeadersAlreadySentException))
      #4 {main}
      Previous exception:
      exception 'yii\web\HeadersAlreadySentException' with message 'Headers already sent in /home/mahdikas/public_html/guestbook/controllers/PostController.php on line 117.' in /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/web/Response.php:366
      Stack trace:
      #0 /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response-&gt;sendHeaders()
      #1 /home/mahdikas/public_html/guestbook/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response-&gt;send()
      #2 /home/mahdikas/public_html/guestbook/web/index.php(12): yii\base\Application-&gt;run()
      #3 {main}
  </code></pre>
  <p>In the postController I have this code:</p>
  <pre><code>public function actionAdd_comment()
  {
    //print_r($_POST);
    $model = new \app\models\Comments;
    if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;validate()) {
      $model-&gt;comment_date = date('Y-m-d H:i:s');
      if ($model-&gt;save()) {
        echo 'Thanks for your comment.';
      } else {
        echo 'Failed!';
      }
    }
  }
  </code></pre>
  <p>which line 117 in the error is:</p>
  <pre><code>echo 'Thanks for your comment.';
  </code></pre>
  <p>How can I solve this problem?</p>