Help with creating an Alert which sends email


This is my 1st post to this forum. I am a uni student studying Yii. I have been tasked to create a small yii application in the form of an estate agent. So far I have created a small site displaying properties.

Unfortunately I am unable to provide a link to this site, as it is on a secure University site with no public access.

I have been successful in creating the required applications so far, which includes the MySQL database with 5 Tables, User, Vendors, Property, Images and UserAlertsCriterea.

All have been tested using Postman Client in Chrome.

I now need to create:

User Alerts which will be generated each time a new property is added to the system by admin users.

The Alert criteria will be generated by a user after they have registered or at any future point.

The criteria will be based on PostCode, Number of Bedrooms, Min Price and Max Price (price range).

Basically this app needs to send an email to the registered user everytime a new property is added.

My question is:

Should I use an email extension to create this or is there a simply piece of code which will provide this function.

I must add that I am using Yii version 1.1 as the University cannot cope with Yii ver 2.

Any help or advice would be greatly appreciated.


Hi bevmart, welcome to the forum.

A simple and straight mail solution should be found in the contact page of the application template.

Of course you may use some mail extension if you like.

But IMO mail sending functionality weighs less than other things in your next task, so it’s better not to spare much effort in it.

Hi bevmart.

I’m use this extension, It is work for me. PhpMailer Extension.

this is a simple example:


 $mail = new JPhpMailer;


 $mail->Host = '';

 $mail->Port = 465;

 $mail->SMTPSecure = "ssl";

 $mail->SMTPDebug = 2;

 $mail->SMTPAuth = true;

 $mail->Username = '';

 $mail->Password = 'password';

 $mail->SetFrom('', 'subject');

 $mail->Subject = 'Email success!!!';

 $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';

 $mail->MsgHTML('here set your message!!');

 $mail->AddAddress('addressee', 'Tommas');






   Yii::app()->user->setFlash('success',"Email send!!!");



I hope help you !!

Hi guys

Sorry for promoting the "enemy", but when I needed code to send AND RECEIVE email, I found Zend_Mail to be the easiest.

To get Zend working with Yii, you need to activate its auto-loader with something like this:

// To use ZF library.

Yii::import('common.extensions.EZendAutoloader', true);

EZendAutoloader::$prefixes = array('Zend');

EZendAutoloader::$basePath = Yii::getPathOfAlias('common.lib') . DIRECTORY_SEPARATOR;

Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);

//Initialise email

$config = array (

       'username' => 'myUserName',

       'password' => 'myPassword'


$transport = new Zend_Mail_Transport_Smtp('', $config);


$mail = new Zend_Mail();