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 /

Email form special characters coding


Reply


686 Views

Avatar
Thomashv

Community Member, 33 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 "[url="http://www.ssbits.com/newbies/2010/creating-a-simple-contact-form/]Creating a simple contact form[/url]", 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..)