Email Results from Long PHP Script

电子邮件的结果从长期的PHP脚本

Tags: php email
标签: php email

问题 (Question)

I need to process a long PHP script and have the results emailed to the user once the script has completed. How is this done?

我需要一个长期过程的PHP脚本,有结果发送给用户一旦脚本完成。这是怎么做的?

最佳答案 (Best Answer)

You might want to use the mail() function. You need an SMTP server set up on your server to do so. See details in the documentation: http://php.net/mail

Edit: if you use PHPmailer class, you can simply save the pdf and

$mail->AddAttachment("document.pdf");

你可能想用mail()功能。你需要在你的服务器上安装这样一个SMTP服务器。在文档中看到的细节:http://php.net/mail

编辑:如果你使用phpmailer类,你可以把PDF和

$mail->AddAttachment("document.pdf");

答案 (Answer) 2

I'm not sure that you really need to decouple the script from PHP, but if that's really what you are wanting to do, you can set a value in a MySQL table to reflect that the script has finished. Then, run a cron job to check to see if the value in MySQL is set. If so, send out the mail. If not, go back to sleep and check again next minute.

我不知道,你真的需要脚本从PHP脱钩,但如果这真的是你想做的,你可以在一个MySQL表设定值来反映,脚本完成。那么,来看看在MySQL的值设置运行cron作业。如果是这样的话,发送邮件。如果没有,回去睡觉,再检查下一分钟。

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/22081441