使用php邮件功能发送电子邮件 - 变慢[关闭]

I have set up a php function to send email when a button is clicked using isset($_POST['id']).

I am receiving the mail correctly but its takes approximately 8 sec to navigate to the next page.

I know it will take a bit of time to login into mail server and sending the mail.
Is there any way to avoid the latency, e.g. by doing it as a background process?

when button is clicked that time you can call the AJAX, you can set the loader on the page when mail sent that time you can hide the that loader

Well, if it is a background process, you can do it with ajax call.

Ajax is the first answer, but if you want it to be called by server you can just exec('php your_php_code_sending_mail.php param1 param2') ; so the user not even have to load the result page in browser, so you can make your validations in PHP and are not dependant on the user browser. You just need some specific rights, depending on your server configuration.