1

Possible Duplicate:
Creating an email queue in PHP?

My PHP script is sending hundreds of emails. And I want to set gap between these email sending times as 5 mins. I mean, time tap between each 2 emails should be 5 mins. Like one should be sent at 12:45am, second 12:50am and so on.

For that I have tried from command line:

at 08:10am Dec 19
echo "Welcome" | mail -s "Hello world" abc@abc.com

So this works fine, mail is sent at 08:10am. But, how can I do the same from PHP? How can I use AT command of linux from PHP?

Or there is any other easy way?

Community
  • 1
  • 1
  • There are dozens of questions and examples of this out there - you just need to do some research. Basically, you queue up the emails to-be-sent in a database. Then you have a background process (daemon) that periodically sends out a large batch of emails, and marks them in the database as "sent". Using `at` is not appropriate here. For example: [*Creating an email queue in PHP?*](http://stackoverflow.com/questions/8507693/creating-an-email-queue-in-php) – Jonathon Reinhart Dec 19 '12 at 07:21
  • Yes, but I dont want to intigrate database headhache here, I just want to use Linux command only. So please suggest me. –  Dec 19 '12 at 07:27
  • You will certainly end up with more of a headache if you try and use `at`. It is a hack and a poor design decision, and the application's success will likely follow. But then again, I'm not sure if you care - in that case: [php execute shell command](https://www.google.com/search?q=php+execute+shell+command). The world is at your fingertips. Embrace it. – Jonathon Reinhart Dec 19 '12 at 07:30

1 Answers1

1

To answer your question:

Calling an external program from PHP can be done using many approaches. One of them is passthru() and giving it the same complete command string you would've written by hand.

Other functions you can use for this are:

popen() // Opens process file pointer
exec() // Execute an external program
system() // Execute an external program and display the output
passthru() //- Execute an external program and display raw output
pcntl_exec() // Executes specified program in current process space
`at` // backtick operator

As a side issue:

Email queueing would be better suited for this indeed - using at is a simple hack for what you're trying to accomplish.

Mihai Stancu
  • 14,701
  • 2
  • 30
  • 49