Codeigniter Email error handling

后端 未结 3 1150
[愿得一人]
[愿得一人] 2020-12-18 18:54

The CI Email send() function only returns true or false. Is there a way to get a more detailed reason as to why a sending failed? I\'m using SMTP.

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-18 19:57

    You can further inspect what happened by using the email debugger:

    $r = $this->send(FALSE);
    if (!$r)
      $this->email->print_debugger()
      ;
    

    From the Codeigniter Email Class Reference.

    If you need the debugger output as a string, you can just catch the output with an output buffer:

    $errors = array();
    ... # Loop
    $r = $this->send(FALSE);
    if (!$r) {
      ob_start();
      $this->email->print_debugger();
      $error = ob_end_clean();
      $errors[] = $error;
    }
    ... # Loop end
    

    Codeigniter in more recent versions requires an explicit FALSE for the $auto_clear parameter of the email->send() function in order to not clear the message and the debugging, effectively killing the debugger function if you fail to pass the FALSE.

提交回复
热议问题