If you send email in PHP with any library through SMTP server, the process will take a while (2 seconds or more). The process isn't necessary to be sequential. Clients don't need to wait and know the sending process had finished or not. So, the sending process is better to be run as background process. If you use Linux, you can use exec method. If you're in Windows environment, you can use popen method. Then you send the result to the background.
In Linux, you can use wget command to be executed to access email sending application script. The message contents can be setup and maintain in database before this action is run.
exec("wget -qO- http://domain.com/send.php &> /dev/null &");
Or you can pass the contents directly as parameters for PHP arguments which is executed.
exec("php /path/to/your/mailer/script \"arg1\" \"arg2\" > /dev/null 2> /dev/null &");
If you are in Windows
pclose(popen("start /B php /path/to/php/script \"arg1\" \"arg2\"","r"));
Comments
Post a Comment