Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Custom email template

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 3098 Views
  • karibe
    Avatar
    Community Member
    56 Posts

    Custom email template Link to this post

    Hello

    I'm looking for solution how to add custom email template on user defined form ( contact form ) submits .

    When form is emailed it looks like it using Page.ss which is bad for me:)
    How to add customized template for emailed submitted user form?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Custom email template Link to this post

    There's 2 solutions:

    1. You make a contact form in code, rather than use the 'contact form' in the CMS - this way you get full control over making it. See the 3rd tutorial for more information on this.

    2. Subclass UserDefinedForm, and hack the code so it chooses a different template. (Not the best solution).

    Cheers,
    Sean

  • blacky
    Avatar
    3 Posts

    Re: Custom email template Link to this post

    can u help to place dropdown controls from middle of the page ... help me please

  • karibe
    Avatar
    Community Member
    56 Posts

    Re: Custom email template Link to this post

    OK, I used http://doc.silverstripe.com/doku.php?id=email_template end works almost perfect but there are three problems:

    1. How to add translated validation messages? Page is in Polish and have to translate validation messages
    2. How to add proper encoding to email? I have bad characters when email is submitted
    3. How to add confirmation message that the email has been send

       function doContactForm ( $data, $form )
       {
          $submission = new ContactFormSubmission();
          $form->saveInto($submission);
          $submission->write();
          // send email
          $email = new Email_Template();
          $email->ss_template = "ContactFormEmail";
          $email->populateTemplate($submission);
          $email->subject = $submission->val( "Subject" );
    $email->from = $submission->val("Email");
    $email->to = "info@somedomain.pl";
          $email->send();
          // ---
          Director::redirectBack();
       }

    Template:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>

    <head>
    </head>
    <body>

    <p class="body">

    <p>Wiadomość wysłana przez $Name z formularza kontaktowego:</p>

    $Content
    </p>

    </body>
    </html>

  • karibe
    Avatar
    Community Member
    56 Posts

    Re: Custom email template Link to this post

    Ok now I need only two answers:)

    3. How to add confirmation message that the email has been send?

    I had to add SubmittedContactArticlePage.ss and works perfect:)

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Custom email template Link to this post

    Just before Director::redirectBack() you can call:

    $form->sessionMessage('Thanks, you've been signed up', 'good');

    Cheers,
    Sean

  • karibe
    Avatar
    Community Member
    56 Posts

    Re: Custom email template Link to this post

    Great

    Are there some messages like 'good' for replacing validation messages?

    3098 Views
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.