PHP要求 - 失败时的响应

时间:2012-11-12 11:54:31

标签: php require

我正在使用ajax调用从我的联系表单发送消息。但是,我想将服务器响应打印回用户,如果成功或失败,我想报告是否由于某种原因缺少class.phpmailer.php,但这对我不起作用,那么怎么可能我在需要失败时显示自定义错误消息?

require "class.phpmailer.php"; or die("<span style='color:red;'>Tiedosto class.phpmailer.php puuttuu! Viestin lähetys epäonnistui!</span>");

2 个答案:

答案 0 :(得分:1)

您需要先检查文件是否存在然后进行导入,如果找不到该文件,则会将消息显示给用户。

if(file_exists('class.phpmailer.php')){ 
    include "class.phpmailer.php"; 
}else{ 
    echo"<span style='color:red;'>Tiedosto class.phpmailer.php puuttuu! Viestin lähetys epäonnistui!</span>"; 
}

答案 1 :(得分:0)

要求生成一个E_COMPILE_ERROR,它在您的IF中无法捕获。