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.

General Questions /

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

Is there a way to send "New User" emails


Reply


7 Posts   1461 Views

Avatar
toddmkimball

Community Member, 13 Posts

30 April 2010 at 4:19am

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

Avatar
swaiba

Forum Moderator, 1804 Posts

30 April 2010 at 7:56pm

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.

Avatar
toddmkimball

Community Member, 13 Posts

1 May 2010 at 12:53am

Edited: 01/05/2010 12:54am

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

Avatar
toddmkimball

Community Member, 13 Posts

1 May 2010 at 1:36am

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

Avatar
swaiba

Forum Moderator, 1804 Posts

4 May 2010 at 8:46pm

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;
      }
   }
}

Avatar
toddmkimball

Community Member, 13 Posts

7 May 2010 at 4:53am

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

Avatar
swaiba

Forum Moderator, 1804 Posts

6 August 2010 at 9:08pm

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