We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36426
    • 197 Posts
    Quote from: BobRay at Aug 06, 2018, 07:05 PM
    Thanks for reporting back.

    Are you saving timestamps or human-readable dates there? If it's the latter, it will be difficult (but not impossible) to do date arithmetic on them (e.g., "you've been a member for 2 years and 3 months").

    I should have remembered that the modUser object already has a createdon field (added somewhat recently), but not an editedon field. Since you're extending modUser, that could have caused your troubles. Using a different name for that field might have made it work as a date field.

    Hi thanks Bob, well I thought everything was working now, but for some reason there is another issue.

    I set up the postHooks field in register so it would email the Admin when a new user registers. I just called it like this:

    &postHooks=`notifyAdmin`


    and then my snippet is the standard example:

    <?php
    $message = 'Hi, a new User has registered on your site: '.$hook->getValue('username')
     . ' with email '.$hook->getValue('email').'.';
    $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,'Test');
    $modx->mail->set(modMail::MAIL_SENDER,'Test');
    $modx->mail->set(modMail::MAIL_SUBJECT,'New App User Registration');
    $modx->mail->address('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: '.$err);
    }
    $modx->mail->reset();
    /* tell our snippet we're good and can continue */
    return true;


    (obviously with [email protected] changed in both places to my actual email address - which may I add is an email that uses the same domain so shouldn't get blocked or rejected etc)

    But the modx Log just gives me this:

    [2018-09-17 14:53:02] (ERROR @ /public_html/core/cache/includes/elements/modsnippet/33.include.cache.php : 13) An error occurred while trying to send the email: 



    Has something changed with the newer versions of PHP that I need to alter the snippet, or can anyone else spot what is wrong. Not sure how to diagnose this further really. I've checked the email logs on the server and such and can't find anything there either. sad

    Thanks for any help.
      Yorkshire UK based hosting provider: https://www.simulant.uk
      • 38783
      • 571 Posts
      Does it work if you change

      $modx->mail->set(modMail::MAIL_SENDER,'Test');
      


      to...

      $modx->mail->set(modMail::MAIL_SENDER,'[email protected]');
        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 3749
        • 24,544 Posts
        On some hosts, the EMAIL_FROM address must have an email account with the host. That's the most common cause of email failure in my experience.

        FWIW, I send all emails through Mailgun, which is free for several thousand emails per month and greatly improves deliverability, though it takes some effort to set up.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 36426
          • 197 Posts
          Quote from: andytough at Sep 17, 2018, 06:33 PM
          Does it work if you change

          $modx->mail->set(modMail::MAIL_SENDER,'Test');
          


          to...

          $modx->mail->set(modMail::MAIL_SENDER,'[email protected]');

          Thanks that did the trick! It is now working smiley
            Yorkshire UK based hosting provider: https://www.simulant.uk