Mail extension

All the details are here:

http://www.yiiframework.com/extension/mail/

Hope it’s of use to someone! I use it in at least three applications so far.

All comments welcome

Jonah, the download file is missing in google code…is there another way for us to get it?

Thanks

Alright, I made a download file. I was hoping people would just get it with subversion

Here it is: http://code.google.com/p/yii-mail/downloads/list

How it works compared to Zend_Mail?

Wouldn’t know, I’ve never used Zend_Mail. Is it good? I’m happy with SwiftMailer though - it’s pretty solid.

EDIT: I added an example to the extension page, even though there are more examples in the phpdoc. I did this because some people don’t care to look at the code unless they see examples first. Here it is: http://www.yiiframework.com/extension/mail/#doc

~Jonah

jonah

Well, yes. Zend_Mail is good enough for me. SwiftMailer wrapper looks good. Very good.

This is my controller’s code:




/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		$model=new Profiles;

		$user = new Users;

		// Uncomment the following line if AJAX validation is needed

		 $this->performAjaxValidation($model);


		if(isset($_POST['Profiles']))

		{

			$model->attributes=$_POST['Profiles'];

			$user->username=$model->faculty_id_no;

			$user->salt=genRandomString();

			$this->tmpPassword = genRandomString();

			$user->password=Users::encrypting($model->birthday,$user->salt);

			$user->createtime=time();

			$user->lastvisit=time();

			$user->role_id=1;

			$user->email=$model->contact_email;

			//var_dump($user->save());

			if($model->validate())	{

				if($user->save())	{

					$model->user_id=1;

					$model->user_id=$user->id;

					if($model->save())	{

						//email the new password

						$message = new YiiMailMessage;

						$message->setBody('This is test 1 for random password: '.$this->tmpPassword, 'text/html');

						$message->subject = 'System generated password test 1';

						$message->addTo($model->contact_email);

						$message->from = Yii::app()->params['adminEmail'];

						Yii::app()->mail->send($message);


						$this->redirect(array('view','id'=>$model->user_id));

					}

				}

			}

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}



and in my config/main:




// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',	

		'application.modules.global.models.*',

		'application.extensions.debugtoolbar.*',

		'ext.mail.YiiMailMessage',

	),

        ....

'components'=>array(

        .....

         'mail' => array(

 			'class' => 'ext.mail.YiiMail',

 			'transportType' => 'php',

 			'viewPath' => 'application.views.mail',

 			'logging' => true,

 			'dryRun' => false

 		),

        ...

        )

	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'mjkulet@yahoo.com',

	),



No error was produced,so I expected that I will receive the email. But none.

Kindly point out what I missed.

Hi,

I am a novice to Yii framework and I was trying to use your extension.

I have a little problem configuring your extension in my framework.

I want to use SMTP transport so I defined the transport type as smtp but how do I define my transport now. If i try to use


'transport'=>Swift_SmtpTransport::newInstance('smtp.gmail.com', 465,'sslv')

  ->setUsername('username')

  ->setPassword('password'),

php doesnt recognizes Swift_SmtpTransport file.If i try to declare them alter in mycontroller it says YiiMail.transport is readOnly. So where and how should I declare transport and mailer variables

$transport is a protected property of YiiMail class, it can’t be set directly from config. Try this instead:




'transportOptions' => array(

	'host' => '...',

	'port' => '...',

	'encryption' => '..',

	'username' => '...',

	'password' => '..',

),



I think that Yii Applications should have a Mail component out of the box