Hi all,
I've just migrated a friend's website from DotNetNuke to ModX and, after adding the 50-odd users am now trying to send a mass email to them letting them know how to reset their auto-generated passwords. The snippet works great and sends out the emails (I'm sending all emails temporarily to my own email address in order to validate they are being created correctly) but it appears that modPHPMailer is creating
duplicate emails, as I get two of every email in my Inbox.
Has anyone ever seen this behavior? I'm using MODX Revolution 2.3.2-pl (traditional).
My snippet content is below if you are interested. I've purposely obfuscated all sensitive information using COMPANY and NAME as substitutes for the real thing, so the content may look a bit weird in places...
<?php
// create PDO query
$c = $modx->newQuery('modUser');
$c->leftJoin('modUserProfile','Profile');
// select columns of interest...
$c->select(array(
'modUser.*',
'Profile.fullname',
'Profile.email'
));
$users = $modx->getCollection("modUser",$c);
$emailed = '';
foreach($users as $user){
$userArray = $user->toArray();
$name = $userArray['fullname'];
$email = $userArray['email'];
$username = $userArray['username'];
$message = "Hello " . $name . ",<br/><br/>The COMPANY website has undergone a recent update which required that we create a new user profile for you. To ensure your member profile is secure and that you continue having access to member-only content on our site, <span style=\"text-decoration: underline;\">we are asking that you reset your user password</span>. To do this, please follow the instructions below:<br/><br/>
1) Visit our \"Forgot Password\" page via the following URL: http://COMPANY.com/forgot-password.html <br/>
2) Enter either your COMPANY username: <strong>" . $username . "</strong>, or the email address we have on file for you: <strong>" . $email . "</strong> in the webform and click Submit. <br/>
3) You will receive an email shortly afterwards with a link to reset your password and the temporary password assigned to you (<em><strong>make sure to check your Spam/Junk folder if you do not receive it within 10 minutes or so of submitting this form</strong></em>). Copy the temporary password, click on the link in the email and then enter your COMPANY username: <strong>$username</strong> and the temporary password into the Login Form you are presented with. <br/>
4) Once you are successfully logged in, you will be on the Member Page area. Click the link on that page that says \"change your password\" (it will be one of the links in yellow text) and follow the steps to set your new, permanent password.<br/><br/>
If you have any questions during this process, please get in touch with us at [email protected] or via phone at 555.555.5555.<br/><br/>
We look forward to continuing to serve your reporting needs via our new website and hope you like our new look!<br/><br/>
Sincerely,<br/><br/>
NAME President, <strong>COMPANY</strong><br/>
COMPANY.com<br/><br/>
<img src=\"http://COMPANY.com/assets/template/images/logo_sm.png\"> ";
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,'[email protected]');
$modx->mail->set(modMail::MAIL_FROM_NAME,'COMPANY');
$modx->mail->set(modMail::MAIL_SUBJECT,'Your COMPANY Login');
$modx->mail->address('to','[email protected]');
$modx->mail->address('reply-to','[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
if ($modx->mail->send())
$emailed = $emailed . $email . "<br/>";
$modx->mail->reset();
}
return $emailed;
Thanks for any help you can provide,
Sandman7