How To Use Multiple Contact Form In A Single Yii Application

How can we use multiple contact us form just like in the blog example in a single yii application. i.e. when someone contact us with the form then an email should be send to the Email that we specified in the config file.

But I want to use multiple contact us form with different email addresses.

So how can I do this ?

Make it a widget and set the mail to address in the widget not in the main config. You can use extensions like this for example http://www.yiiframework.com/extension/yiimailer/ that allow you to set the send to address in the view or in your case the widget. Look up here how to do a widget…there is plenty of documentation for you to execute this task on the yii site.

thanks dear for your reply.

Actually I have 3 types of contact us pages. i.e Contact with Admin, contact with Director, Contact with Producer. and and every page have a contact form through which we can contact with the concern person i.e. Director, Admin, Producer. and I want that when the contact us form is filled then this data should be sent the concern person’s email address.

So how can I do this ?

thanks in advance.`

The answer is still the same.

Make a contact us widget

make a public var $email in your widget and set it in your view since it’s static and wont change.

in admin page


$this->widget('contactUs', array(

$emailTo = 'admin@email.com'

));

in director page view use something like this:


$this->widget('contactUs', array(

$emailTo = 'director@email.com'

));




<?php

class ContactWidget extends CWidget {


public $emailTo;


 public function run() {

 $model = new ContactFormModel; 

$form= $this->beginWidget('CActiveForm', array(

'id'=>'contact-form',  

'action'=>array('site/contact/'),

));	

echo $form->textField($model,'contact',array('placeholder'=>'Enter Name',class=>'form-control'));

echo $form->passwordField($model,'comment',array('placeholder'=>'Comment',class=>'form-control'));   

echo CHtml::submitButton('Send Message',array(class=>'form-control'));

 $this->endWidget(); } } ?>

If the email address could change you should save them in a db or file to be edited.

I’m not going to write the whole thing for you.

You should look up Yii widgets. You will need to pass the $emailto variable to your function that is going to send emails.

You could opt out of a widget and just renderPartial if all of your contact views are in the same controller (if they aren’t id make a widget).

I was looking up something and saw a random link for this tutorial. Here is a simple example / tutorial