简体   繁体   中英

How to send email in background in PHP?

I have a user registering form. When user registers, all the data entered will be saved in database and confirmation email will be sent to user. But I do not want the user to wait for the email sending. So I want it sent in the background. Even if the user goes to another page, the task must be running in the background.

I tried this article , but it is not working. I also do not want to use database for that as well. How can I achieve it?

**USE THIS CODE ON BOTTOM OF PAGE**

function partialResponse()
            {
                $response=array();
                ignore_user_abort(true);
                ob_start();
                echo json_encode($response);
                header("Status: 200");
                header($_SERVER["SERVER_PROTOCOL"] . " 200 Ok");
                header("Content-Type: application/json");
                header('Content-Length: '.ob_get_length());
                ob_end_flush();
                ob_flush();
                flush();
            }

AFTER THAT CALL THIS FUNCTION BEFORE SENDING THE EMAIL

INSIDE CORE PHP partialResponse() OR INSIDE THE $this->partialResponse()

EXAMPLE:

partialResponse(); sendEmail();

$this->partialResponse(); $this->email->send();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM