Jump to:

23461 Posts in 18908 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Is there a way to send "New User" emails

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1403 Views
  • toddmkimball
    Avatar
    Community Member
    13 Posts

    Is there a way to send "New User" emails Link to this post

    I have searched the forum and docs and am unable to determine if the is a way to send a new user, added via the CMS security tab, their credentials when they are created. Has anyone done this or developed a solution?

    Regards,
    Todd M. Kimball

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Is there a way to send "New User" emails Link to this post

    I have not done this before, but I'd recommend using a custom/decorator Member class and adding the email sending in an overridden onAfterWrite.

  • toddmkimball
    Avatar
    Community Member
    13 Posts

    Re: Is there a way to send "New User" emails Link to this post

    Thanks, that did the trick. However, I'm getting 2 email notifications instead of one. I'm using this to decorate, test code no flame about not using the email class please 8):

    <?php
    class MemberEmailNotification extends DataObjectDecorator {

    function onAfterWrite() {
    mail("me@email.com", "test", "did you get this?");

    parent::onAfterWrite();
    }
    }
    ?>

    Could this be a result of calling parent::onAfterWrite()? If I don't call it will I be omitting any necessary logic in the parent classes onAfterWrite method?

    Regards,
    Todd

  • toddmkimball
    Avatar
    Community Member
    13 Posts

    Re: Is there a way to send "New User" emails Link to this post

    Plan B, I'm attempting to use a native function of the Member class, sendInfo(), instead of writing my own logic to send an email. It works, but the email has variable symbols included instead of the values associated with the symbols. Here is a snippet of the email:

    <--- Begin Snippet --->
    Welcome, $FirstName.

    Thanks for signing up to become a new member, your details are listed below for future reference.

    You can login to the website using the credentials listed below:

    Email$Email
    Password:$Password
    Contact Information
    <--- End Snippet --->

    As you can see, it's as if the variables aren't being parsed. Any ideas on this one?

    Regards,
    Todd

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Is there a way to send "New User" emails Link to this post

    how about doing something like this (again untested...)

    class MemberEmailNotification extends DataObjectDecorator
    {
       var $bSendEmailFlag;

       function onAfterWrite()
       {
          parent::onBeforeWrite();
          $this->bSendEmailFlag = true;
       }

       function onAfterWrite()
       {
          parent::onAfterWrite();
          
          if ($this->bSendEmailFlag)
          {
             mail("me@email.com", "test", "did you get this?");
             $this->bSendEmailFlag = false;
          }
       }
    }

  • toddmkimball
    Avatar
    Community Member
    13 Posts

    Re: Is there a way to send "New User" emails Link to this post

    Thanks again for the latest suggestion. However, I am now trying to use existing methods to generate the email (see my previous response). If anyone could provide any insight into the Member->sendInfo() method that wold be great.

    Regards,
    Todd

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Is there a way to send "New User" emails Link to this post

    I know I am replying to an old thread that you, toddmkimball, have moved on from, but I recently had a need to do this and since my method was untested I thought I'd post back the completed working version the way I found to work for a dataobject in general when creating it and ensuring you only get one execution of the code... note does not apply to re-saves...

    function onAfterWrite()
    {
       parent::onAfterWrite();

       if (isset($this->Created))
       {
          //do on after wirte action only once
       }
    }

    Barry

    1403 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.