如何从imap_open捕获错误消息?

时间:2019-10-31 12:54:16

标签: php laravel imap-open

我正在尝试使用imap_open建立连接,并且试图将错误消息返回给最终用户。但是,每次遇到错误,执行都会停止。

try {
    $mbox=imap_open( "{" . $data['imap_host'] . ":" . $data['imap_port'] . "/novalidate-cert}INBOX", $data['email'], $data['imap_password'] );
    imap_close($mbox);
    return [
        'success' => true
    ];

}catch (Exception $e) {
    return [
        'success' => false,
        'message' => $e->getMessage() //imap_last_error()
    ];
}

使用上面的代码,它会因错误而停止

"message": "imap_open(): Couldn't open stream {mail.example.com:143/novalidate-cert}INBOX",
    "exception": "ErrorException",

我尝试通过添加@imap_open来解决此错误,这就是为什么它未在$e->getMessage()上返回任何错误消息的原因。我尝试将$e->getMessage()替换为imap_last_error(),但没有任何反应。

我想念什么?如果在此过程中遇到任何错误,我如何捕捉到该错误?

0 个答案:

没有答案