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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵