erick.chali erick.chali - 6 months ago 8x
PHP Question

PHPMailer response

I'm using phpmailer to send email with the function:

function send_email($address, $message){
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Host = "";
$mail->SMTPAuth = true;
$mail->Username = "";
$mail->Password = "password";
$mail->SMTPSecure = "tls";
$mail->Port = 587;

$mail->From = "";
$mail->FromName = "Name";
$mail->addAddress($address, "Cust. name");


$mail->Subject = "Nueva clave";
$mail->Body = "<i>".$message."</i>";
$mail->AltBody = "This is yout password.";

return true;
return false;

in my php file I set the response header this way:

header('Content-Type: application/json');
after the process that needs to be made I handle email this way:

if(send_email('', $message))
array_push($response, 'email sent');
array_push($response, $new_password);
echo json_encode(array('errors'=>$errors, 'response' => $response));
array_push($errors, 'email not send');
array_push($errors, $new_password);
echo json_encode(array('errors'=>$errors, 'response' => $response));

normally I expected a response from the server like: Object[errors[],response[]] just as several times I have done this, however instead I'm receiving this as an answer JSON RESPONSE

why I'm getting this response, do I need any other configuration that was not set.


You are including debug output in your response, which is not valid JSON. Just do this to turn it off:

$mail->SMTPDebug = 0;