Contact Form- Send Mail To Email Address Stored In Db Table

Hi Guys!

First I wanna say hello to everyone, 'cause this is my first post here :)

I’ve already created a model for DB table. Now I created a custom form, with who I want to get some data for a custom query (get email address for particular ‘addid’ which is primary key stored in email column) . I wanted to send mail by using contact form to the related email address for the ‘addid’ in the table.

for this, I created contactpublisher.php in the view of model.

my model is Add controller is AddController view is add/contactpublisher.php

view code contactpublisher.php


/* @var $this SiteController */

/* @var $model ContactForm */

/* @var $form TbActiveForm */

$this->pageTitle=Yii::app()->name . ' - Contact Add Publisher';





<h2>Contact Add Publisher</h2>

<?php if(Yii::app()->user->hasFlash('contact')): ?>

    <?php $this->widget('bootstrap.widgets.TbAlert', array(


    )); ?>

<?php else: ?>


If you have business inquiries, please fill out the following form to contact the publisher of this add.


<div class="form">

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(







)); ?>

<?php echo "<br>"; ?>

	<?php echo $form->errorSummary($model); ?>

    <?php echo $form->textFieldRow($model,'name'); ?>


<?php echo $form->textFieldRow($model,'email'); ?>

    <?php echo $form->textFieldRow($model,'subject',array('size'=>60,'maxlength'=>128)); ?>

    <?php echo $form->textAreaRow($model,'body',array('rows'=>4, 'class'=>'span5')); ?>


	<div class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton',array(





        )); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->

<?php endif; ?>

I put the link for contactpublisher form in the view of add:- view.php as



array('label'=>'Contact Add Owner', 'url'=>array('contactpublisher', 'id'=>$model->addid)),



my question is how to find the email address saved in table for the particular addid, I already tried this by using


but this is not working at all.

maybe someone can help me out with a small snippet :)

cheers and thanks to everyone in advance!!

Can you show your code from controller action?

Do you get some error?

controller code-

       class AddController extends Controller


          public function actionContactpublisher()


          $model=new ContactForm;












				$headers="From: $name <{$model->email}>\r\n".

					"Reply-To: {$model->email}\r\n".

					"MIME-Version: 1.0\r\n".

					"Content-type: text/plain; charset=UTF-8";


				Yii::app()->user->setFlash('contact','Mail is sent to the add publisher, Please wait publisher will reply soon... ');








no any error… i think problem is that addid value is not passed to the contactpublisher form from the view page of add model

add/view.php code-


/* @var $this AddController */

/* @var $model Add */






	array('label'=>'Contact Add Owner', 'url'=>array('contactpublisher', 'id'=>$model->addid)),



<h1>View Add #<?php echo $model->addid; ?></h1>

<?php $this->widget('bootstrap.widgets.TbDetailView', array(

















How to pass addid value to the contactpublisher form??

Add it to render();

render($this->render('contactpublisher',array('model'=>$model, 'addid'=>$wahtever)));

like this??