Yii Framework Forum: New thread for sending email - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

New thread for sending email Rate Topic: -----

#1 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 230
  • Joined: 26-September 09

Posted 15 March 2010 - 08:23 AM

Hi all,

I used to develop web application using Java. For example in user registration to our web app, we usually send the activation code via email. In Java, usually I create a new thread and put the email sending process in this new thread so it does not blocked the rest of the code execution. I am relatively new to PHP, what should we do it in Yii/PHP?

Thank you for your help.

Kind regards,

Daniel
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 March 2010 - 08:28 AM

You could add your emails to a queue (whatever that is, e.g. a db table) and use a separate process (or a cron job) to process that queue. One implementation for that is available from PEAR, but never used it though.
0

#3 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 March 2010 - 08:58 AM

Alternatively you can create a console command (or pure php, whatever you like) and run it as background process (so it won't block php execution).

Example:

exec('/usr/bin/php -f /var/www/index.php sendmail "to@address.com" "title" "body"  > /dev/null &');


You may put that into a php class so you can simply do:

$mail = new Mail;
// set receiver, subject, ...
$mail->send();

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users