Hi all!
It might seem weird but i can’t seem to get Modx to sent emails (i need smtp, authenticated...i need swiftmailer, it works!) After scavenging code upon code, i finally got the Login.Register snippet to send an email (only the link to Login.ConfirmRegister... sweat - sweat;!)
to do this, i modified ’core\components\login\processors\register.php’ as follow;
i commented out theses lines;
<?php
// ---------------------------------------------------------------------------------------------------------------------
// /* send either to user's email or a specified activation email */
// $activationEmail = !empty($scriptProperties['activationEmail']) ? $scriptProperties['activationEmail'] : $user->get('email');
// $subject = $modx->getOption('activationEmailSubject',$scriptProperties,$modx->lexicon('register.activation_email_subject'));
// $login->sendEmail($activationEmail,$user->get('username'),$subject,$emailProperties);
// ---------------------------------------------------------------------------------------------------------------------
I then added my minimalist replacement code;
<?php
$recipientMail = $user->get('email');
$recipientName = $user->get('username');
$subject = $modx->getOption('activationEmailSubject',$scriptProperties,$modx->lexicon('register.activation_email_subject'));
// $activationEmail seems not to do anything with swiftmailer - or is it me? (help)
// I used $confirmUrl as a quick fix (no template processing?)
$activationEmail = !empty($scriptProperties['activationEmail']) ? $scriptProperties['activationEmail'] : $user->get('email');
$modx->getService('mail', 'mail.modSwiftMailer');
$modx->mail->address('to', $recipientMail, $recipientName);
$modx->mail->address('from', '[email protected]', 'xxxx.com account activation');
$modx->mail->subject($subject);
$modx->mail->body($confirmUrl);
$modx->mail->send();
It’s not pretty, well tought-about, but it works - For now...
Nice, i then said... but as of now it’s very limited. Only Login.Register has been modified (and simply poorly) to send an e-mail.
My issues (let-alone my mental state):
- My modification is only a temporary fix for registering.
- It ONLY works for registration, since i modified the original file.
- Currently, this modification doesn’t process any e-mail template, it just sends the url to the e-mail address.
After checking out ’core\components\login\model\login\login.class.php’ i got to the sendEmail() function.
<?php
public function sendEmail($email,$name,$subject,$properties = array()) {
if (empty($properties['tpl'])) $properties['tpl'] = 'lgnForgotPassEmail';
if (empty($properties['tplType'])) $properties['tplType'] = 'modChunk';
$msg = $this->getChunk($properties['tpl'],$properties,$properties['tplType']);
$this->modx->getService('mail', 'mail.modPHPMailer');
$this->modx->mail->set(modMail::MAIL_BODY, $msg);
$this->modx->mail->set(modMail::MAIL_FROM, $this->modx->getOption('emailsender'));
$this->modx->mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('site_name'));
$this->modx->mail->set(modMail::MAIL_SENDER, $this->modx->getOption('emailsender'));
$this->modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$this->modx->mail->address('to', $email, $name);
$this->modx->mail->address('reply-to', $this->modx->getOption('emailsender'));
$this->modx->mail->setHTML(true);
$sent = $this->modx->mail->send();
$this->modx->mail->reset();
return $sent;
}
My questions:
- Is there an easy way to modify the above code to
seemlessly (
snippet(s) must behave as intended) use swiftmailer as ’mailer’?
- Would this be worth as feature request?
Please consider helping... i am building this site non-profit. No clients involved, no timeframe. Basically, it’s a matter of knowledge, to keep my brain challenged as everyday business isn’t satisfying enough.
I’m sure it’ll help some other fellow modx’ers!
Thanks!
Addendum;
Would it be possible to be more clear on the ’Login’ snippet documentation in general? It lacks uniformity ie; all ’Login.*’ snippets should be detailed as if you never even use or heard of the ’Login’ snippet before. Derivated snippets should’nt assume you’ve read everything before, after, in between.
Just my 2 cents! Again - Thanks!