Yii Framework Forum: Sending Data From A Form To My Gmail - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sending Data From A Form To My Gmail Rate Topic: -----

#1 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 29 November 2012 - 10:25 PM

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
        'params'=>array(
		// this is used in contact page
		'adminEmail'=>'my_real_email@gmail.com',
	),


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;
		if(isset($_POST['ContactForm']))
		{
			$model->attributes=$_POST['ContactForm'];
			if($model->validate())
			{
				$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
				$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
				$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";

				mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
				Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
				$this->refresh();
			}
		}
		$this->render('contact',array('model'=>$model));
	}

Look into the code I think the body text ($model->body) should be sent to params['adminEmail'] (in this case this is my_real_email@gmail.com). 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.

Cheers!
0

#2 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 30 November 2012 - 01:50 AM

The PHP mail() function will work fine,
just check your passed parameters as they are set correct or not...
and use $_POST['ContactForm']['name'], $_POST['ContactForm']['subject'] instead of $model->name, $model->subject.. ..
Thanks,
Kiran Sharma.
0

#3 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 30 November 2012 - 10:52 PM

View Postkiran sharma, on 30 November 2012 - 01:50 AM, said:

The PHP mail() function will work fine,
just check your passed parameters as they are set correct or not...
and use $_POST['ContactForm']['name'], $_POST['ContactForm']['subject'] instead of $model->name, $model->subject.. ..

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.

Cheers!
0

#4 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 01 December 2012 - 01:32 AM

are you testing on localhost...???
had you tried on any live mail enable server???
...
Thanks,
Kiran Sharma.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users