Search code examples
phpyii

Automatic email


I am a new user of Yii framwork, and I have implement YiiMail, which works well. But now I want to send mails automatically at the end of each month, is it possible?


Solution

  • Steps are as follows:

    1. Set up a crontab on your server, that will run a PHP command.

      On Windows you can set a scheduled task which will run <yourdir>/protected/yiic-dev.bat with the proper commands to run (take a look at CConsoleCommand), which will send the emails.

      On the production server, you do the same but with php <yourdir>/protected/yiic.php as the cron with the command to run as argument, which will do the same but on a Linux environment (if it's a Windows server, just make a scheduled command for <yourdir>/protected/yiic.bat and the proper arguments)

    2. Send the emails in the corresponding action, by using the mail class (see the documentation for YiiMailer)

    If there are further problems and you run into more specific issues you can't work around, I suggest you make new questions for them.