Reputation: 686
I'm using phpmailer to send email with the function:
function send_email($address, $message){
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->From = "[email protected]";
$mail->FromName = "Name";
$mail->addAddress($address, "Cust. name");
$mail->isHTML(true);
$mail->Subject = "Nueva clave";
$mail->Body = "<i>".$message."</i>";
$mail->AltBody = "This is yout password.";
if($mail->send())
{
return true;
}else{
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('[email protected]', $message))
{
array_push($response, 'email sent');
array_push($response, $new_password);
echo json_encode(array('errors'=>$errors, 'response' => $response));
}
else
{
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
why I'm getting this response, do I need any other configuration that was not set. Thanks
Upvotes: 1
Views: 7813
Reputation: 37730
You are including debug output in your response, which is not valid JSON. Just do this to turn it off:
$mail->SMTPDebug = 0;
Upvotes: 9