Sending Data From A Form To My Gmail

Hello everyone!

After the user filled in information in a form (that is associated with a database table), all the information should be sent to my gmail that I’ve set inside config file main.php


		// this is used in contact page



It obvious to take a look at the actionContact of SiteController that is automatically generated by using gii.

Here is the actionContact of SiteController.

        public function actionContact()


		$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','Thank you for contacting us. We will respond to you as soon as possible.');






Look into the code I think the body text ($model->body) should be sent to params[‘adminEmail’] (in this case this is And the sender is $model->email that the user filled in when submitting the ContactForm. Usually to send an email we should give an email adress and corresponding password and with the help of an Email client like Outlook Express. I don’t see anything like that inside the code. I’ve searched around internet and sounds like I have to install an email server. I’m using XAMPP for my localhost, so I’ve already got Mercury mail server. Should I use that mail server for my localhost? How could I config my Yii code to achieve my goal. In the future I’m going to load my project to a web server so I think they have an email server working together with the web host server.

Thank you for reading my post and hope to see your replies or suggestions.


The PHP mail() function will work fine,

just check your passed parameters as they are set correct or not…

and use[size=2] $_POST[‘ContactForm’][‘name’], [/size][size=2]$_POST[‘ContactForm’][‘subject’] instead of $model->name, $model->subject… …[/size]

Hi the problem is not with my code because I’ve coppied the code from code that is generated by gii. After posting this question, I’ve tried many things like these just to install a SMTP server on my localhost. Please take a look at these links!

  1. First try

  2. Second try

3.Third try

All with no luck.

Now i’m trying to use Yii-mail extension. And I’m facing another problem like described here

So what is your suggestion?

Thank you for trying to help me.


are you testing on localhost…???

had you tried on any live mail enable server???