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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?