Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Email form special characters coding

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

Page: 1
Go to End
Author Topic: 622 Views
  • Thomashv
    Community Member
    33 Posts

    Email form special characters coding Link to this post

    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 = '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
          //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..)

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.