helloxielan 2018-06-18 09:20 采纳率: 0%
浏览 44

Ajax和PHPMailer错误

I'm improving a code, but i'm getting some troubles.

I'm trying to send an email to one of my users. If the email exist i got no problem, instead if doesn't exist the website app explode.

This is my js code using ajax:

callAjax(url, paramsInsert, true, function (data) {
    if (data.success) {
        modal("OK", "<h3>ALL OK</h3>", "OK");
    } else {
        modal("error", "<h3> ERROR </h3>", "Error");
    }
});

And this is my Ajax function:

function callAjax(url, parametros, load, funcion) {

if (load) {
    var element = document.createElement("div");
    element.id = "loadBackground";
    element.className = "backLoad";
    document.body.appendChild(element);
    document.getElementById("contenido").innerHTML = '<div class="loadImage"><div class="col-xs-12 col-sm-12 col-md-12"><div class="col-xs-4 col-sm-4 col-md-4"></div><div class="col-xs-4 col-sm-4 col-md-4"><img class="center-block" src="img/ajax-loader.gif" /></div><div class="col-xs-4 col-sm-4 col-md-4"></div></div></div>';
}

var ajax = new XMLHttpRequest();

ajax.onreadystatechange = function () {
    if (ajax.readyState === 4) {
        //var datos = JSON.parse(ajax.responseText);

        var jsontext = ajax.responseText;

        var content = eval('(' + jsontext + ')');
        //if (content.success) {
        funcion(content);
        if (load) {
            document.getElementById("contenido").innerHTML = '';
            document.body.removeChild(document.getElementById("loadBackground"));
        }
        // }

    }
};
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.send(parametros);

}

If mail is incorrect i'm getting this error on console of the broswer:

jsontext = "SMTP Error: The following recipients failed: gjdfhgdf@dfgndfjkgd.com: : Recipient address rejected: Domain not found ↵{"success":false}"

The problem is that i don't get inside the else "callAjax" function.

How can i get inside that else when i get an error on wrong mail?

EDIT:

My php code is something like this:

$enviarEmail = $this->sendMAIL($_SESSION['idenUser'], $totalconDescuento, $envioDesc, $_POST['sin_assistente']);

    if (!$enviarEmail) {
        echo json_encode(['success' => false, 'jsontext' => 'Error']);
    } else {
        echo json_encode(['success' => true, 'jsontext' => 'OK']);
    }

Still getting same error:

jsontext = "SMTP Error: The following recipients failed: gjdfhgdf@dfgndfjkgd.com: : Recipient address rejected: Domain not found ↵{"success":false,"jsontext":"Error"}"

I also tried to add parameters when i create new PHPMailer:

$mail = new PHPMailer(false);

    $mail->isSMTP();
    $mail->SMTPDebug = false;
    $mail->do_debug = 0;

Found on this post: Disable PHPMailer error messages

Solution:

I found through functions this code:

if (!$mail->send()) {
        echo $mail->ErrorInfo;
        $estado = false;
    }

So i just commented fisrt lane to disable Errorinfo print :)

  • 写回答

1条回答 默认 最新

  • Lotus@ 2018-06-18 09:46
    关注

    To get into that else you need to make sure that data.success contains a value that will not be considered true, and that's up to what you return from PHP, not what's in your JS.

    If you want to process the return value as JSON, you need to actually return JSON from your PHP - which your example jsontext is not.

    In your PHP it would be something like:

    if (!$mail->send()) {
        echo json_encode(['success' => false, 'jsontext' => $mail->ErrorInfo]);
    } else {
        echo json_encode(['success' => true, 'jsontext' => 'OK']);
    }
    
    评论

    报告相同问题?

    悬赏问题

    • ¥15 存储过程或函数中的结果集类型变量如何使用。
    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信