MODx Revolution 2.0.6 (traditional); Apache ; PHP 5.2.13; PHPMailer 2.0.4;
I have the Login extra working fine. I am now attempting to extend it to send an e-mail notification when a user registers (via the posthooks parameter). My entire snippet code is at the end of this post (so you can read the preamble and skip this if not interested).
I have followed Shaun’s example posthook snippet very closely (ASIDE: I am continually amazed and grateful at the effort Shaun has put into MODx Revolution).
I have validated the code locally using "php -l testxxx.php", but am running PHP 5.3.3 on my Mac. However, the validation was purely to look for silly syntax errors (I removed the <?php and ?> to validate).
Shaun’s sample snippet runs fine, but obviously doesn’t send an e-mail message as the e-mail addresses are meaningless (I hope!). My snipped produces the following error message (copy-and-pasted):
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /data/13/0/91/18/91833/user/93230/cgi-bin/modx/core/cache/wccr/elements/modsnippet/33.include.cache.php on line 27
The problem is something to do with the code starting with the line (which BBEdit says is line 25):
$modx->getService(’mail’, ’mail.modPHPMailer’);
Ideas (not guesses)? Here is the snippet ("wccr_login_notify" is a system setting I added that is the address to which administrative notifications from the login system are to be sent):
<?php
/* Post-hook for Login:Registration. Sends an e-mail message regarding the registration to the membership committee.
Notes:
1. Refer to the documentation for the "login" extra for basic documentation.
Extensions to the sample in the basic documentation:
1. The body of the e-mail message is provided in a template (TPL). The field values are merged using MODx methods.
2. Messages are sent from the e-mail address set in the system settings: "emailsender" (not hard-coded here)
3. Messages are sent to the e-mail address set in the system settings: "wccr_login_notify"
*/
$formPlaceHolderPairs = array (
'username' => $hook->getValue('username'),
'fullname' => $hook->getValue('fullname'),
'email' => $hook->getValue('email'),
'date' => date('Y-m-d H:i')
);
$formTpl = $modx->getObject('modChunk', array( 'name' => 'wccrRegNotifyTpl'));
$message = $formTpl->process($formPlaceHolderPairs);
$emailSender = modx->getOption('emailsender');
$wccrLoginNotify = modx->getOption('wccr_login_notify');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $emailSender);
$modx->mail->set(modMail::MAIL_FROM_NAME, 'WCCR Web Site User Admin');
$modx->mail->set(modMail::MAIL_SENDER, 'WCCR Web Site User Admin');
$modx->mail->set(modMail::MAIL_SUBJECT, 'WCCR: New User Registered');
$modx->mail->address('to', $wccrLoginNotify);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
}
$modx->mail->reset();
return true;
?>