'send back json response message after smtp close

I have a php scirpt that send mails with smtp. When all mails are sent i want to close the smtp and then send back json response to an ajax call

   $mailer->smtpClose();
    $connect->close();
    echo json_encode($valid);

Now the code stops execution on smtp close $mailer->smtpClose();



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source