This is an email extension for yii its pretty straightforward, you add the extension, configure it in main.php and use it in your controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php return array( 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=>'My Web Application', // preloading 'log' component 'preload'=>array('log'), // autoloading model and component classes 'import'=>array( 'application.models.*', 'application.components.*', 'ext.yii-mail.YiiMailMessage', ), // application components 'components'=>array( ... 'mail' => array( 'class' => 'ext.yii-mail.YiiMail', 'transportType' => 'smtp', // change to 'php' when running in real domain. 'viewPath' => 'application.views.mail', 'logging' => true, 'dryRun' => false, 'transportOptions' => array( 'host' => 'smtp.example.com', 'username' => 'myuser', 'password' => 'mypass', 'port' => '465', 'encryption' => 'tls', ), ), ), 'params'=>array( // this is used in contact page 'adminEmail'=>'webmaster@example.com', ), ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public function actionCreate() { $model= new MyModel; // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if(isset($_POST['SomeForm'])) { $model->attributes=$_POST['SomeForm']; if($model->validate()){ if($model->save()){ $message = new YiiMailMessage; $message->setBody('<h1>mets-blog.com</h1>','text/html'); $message->subject = 'Service'; $message->addTo('mets@blog.com'); $message->from = 'your@email.com' you want Yii::app()->mail->send($message); $this->redirect(array('view','id'=>$model->id)); } } } $this->render('create',array( 'model'=>$model, )); } |