Default Contact Page Sending Two Emails

Hi

This problem has been bugging me for days and I can’t get to the bottom of it.

The contact page on my site which is the default contact page that comes out of the box with Yii installation sends it’s email twice. I’m having the same problem using the User Control module but only on the ‘reset password’ page not on the registration page.

I’ve tried all kinds of things to track it down but no luck. I’ve used static count variables to see if the mail function was being called twice somehow but it’s not. It’s not the server because the registration page is fine and I can’t see any real differences.

Here’s the code in the contact action (i commented out refresh in case that was causing it but no change)…




	public function actionContact()

	{

	    

	    Yii::app()->params['activePage']='nobutton';

	    Yii::app()->params['pageTitle']='Contact Us';

	    $this->pageTitle = Yii::app()->name." - Contact Us";

		$model=new ContactForm;

		if(isset($_POST['ContactForm']))

		{

			$model->attributes=$_POST['ContactForm'];

			if($model->validate())

			{

			    $message = $model->name."\r\n\r\n".$model->body;

				$headers="From: {$model->email}\r\nReply-To: {$model->email}";

				mail(Yii::app()->params['adminEmail'],$model->subject,$message,$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));

	}



Anybody else have this problem and if so how did you solve it?

Thanks in advance

Lux

It seems to me the problem with "favicon.ico".

http://www.yiiframework.com/forum/index.php/topic/30769-solved-controller-action-runs-2-times-in-one-load

Hi

Thanks for the response.

If indeed it’s a problem with the browser and favicon what would be the solution?

The other thing that’s odd is it never happens on the registration page but always happens on contact and reset password pages. I just tried the contact page in Opera and the same thing happened. Two emails received :(

Lux

If you don’t have favicon.ico in your web root, then just place it.

Probably even an empty file will do.

It might not be the favicon.ico but some other missing file that your page is trying to load.

Check if there’s a loading error using your browser’s developer tool.

The registration action will alter the user’s state, so that the 2nd call to that action will be ignored or canceled.

But in contact and reminder actions, the user’s state will remain the same and the 2nd call will be processed normally.

Hi

I already had a favicon.ico in the root so I don’t think it’s that.

I’ve also confirmed that the function is being called twice in both firefox and opera.

Still no idea what could be causing it to be called twice though.

Lux

PS: No errors being shown in firebug either.

PPS: Thought I’d solved it when removing the ‘apple-icon’ lines appeared to solve it but the problem re-appeared shortly after so still looking for a solution.