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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Email form special characters coding


Go to End


1812 Views

Avatar
Thomashv

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();
        $form->saveInto($submission);
        $submission->write();
	 	$mailto = $this->Mailto;
	 	if($mailto == '') { $mailto = 'thomas@visionweb.no'; }
		$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
		$email->setTemplate('ContactEmail');
		//populate template
		$email->populateTemplate($data);
		//send mail
		$email->send();
	  	//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..)