Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Email form special characters coding

Go to End



Community Member, 35 Posts

13 September 2012 at 11:46pm

Edited: 13/09/2012 11:47pm

I'm trying to use the SendContactForm function from Aram's tutorial "Creating a simple contact form", and everything works fine except that special characters looks VERY special. Maybe they do get double encoded or something...

Here is the function:

//The function that handles our form submission
	function SendContactForm($data, $form) 
	 	//Set data
	 	$submission = new ContactFormSubmission();
	 	$mailto = $this->Mailto;
	 	if($mailto == '') { $mailto = ''; }
		$From = $data['Email'];
		$To = $this->Mailto;
		$Subject = "Website Contact message";  
		//setting header values
		$Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
		$email = new Email($From, $To, $Subject, $Header);
  		//$email = new Email($From, $To, $Subject);
		//set template
		//populate template
		//send mail
	  	//return to submitted message
		$this->redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

I have tried different kind of encoding on the data array, but since it is an array it doesn't work and set the charset to UTF-8 in the header:

$Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
$email = new Email($From, $To, $Subject, $Header);

Is this a known problem when sending data posted in a form like this? Or is it just me? :)
This is how my characters look like: Ü å å

Anyway if anybody here have experienced similar behaviour, and found a solution to it. It would be great if you could share some of your experience.

PS! Using SS 3.0 (but that shouldn't be relevant to the problem, I suppose..)