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 纯运放实现隔离采样方案设计
  • ¥20 easyconnect无法连接后缀带.com的网站,一直显示找不到服务器ip地址,但是带有数字的网站又是可以连接上的,如何解决
  • ¥15 电脑开机过商标后就直接这样,求解各位
  • ¥15 mysql , 用自己创建的本地主机和用户名 登录不上
  • ¥15 关于#web项目#的问题,请各位专家解答!
  • ¥15 vmtools环境不正常
  • ¥15 请问如何在Ubuntu系统中安装使用microsoft R open?
  • ¥15 jupyter notebook
  • ¥30 informer时间序列预测
  • ¥20 SSR引物多态性分析