Hey guys,
There has been a few previous threads on this which have helped me work out what I need to do but I'm stuck at the last hurdle.
I'm decorating the Member class, adding a bit of code to e-mail a welcome message to users added into the CMS. The e-mail has dynamic data in for the users name, login details and e-mail address. Here's my decorator class (MemberDecorator.php):
<?php
class MemberDecorator extends DataObjectDecorator {
function onAfterWrite() {
parent::onAfterWrite();
if (isset($this->Created)) {
// send e-mail
$From = 'noreply@some.domain';
$To = $this->Email;
$Subject="Your account details";
$Body = '<h3>Your account details</h3>
<p>Hello '.$this->FirstName.' '.$this->LastName.',</p>
<p>This is an automated message from the website to let you know that we\'ve set up an account for you to access the Members Extranet. Here are your details:</p>
<p>Login: <strong>'.$this->Email.'</strong><br />Password: <strong>'.$this->Password.'</strong></p>
<p>If you have any problems with these details, please contact us. Details can be found on the website.</p>';
$email = new Email($From, $To, $Subject, $Body);
$email->send();
}
}
}
?>
I think the code is sound in theory but I'm not accessing the Member properties properly, the e-mail isn't showing up unless I hard-code the "To" variable and then all of the dynamic content in the e-mail is missing. Do I have to query or pass the member record somehow? I could just query the latest entry in the table but that's not elegant. Please help!
Thanks