Does it work if you change
$modx->mail->set(modMail::MAIL_SENDER,'Test');
to...
$modx->mail->set(modMail::MAIL_SENDER,'[email protected]');
$modx->mail->set(modMail::MAIL_SENDER,'Test');
$modx->mail->set(modMail::MAIL_SENDER,'[email protected]');
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.
&postHooks=`notifyAdmin`
<?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;
[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:
I think the problem with your schema is the dbtype and phptype specification of the date fields. Otherwise, I don't see anything wrong with it.
These are the examples I found in the MODX schema:
<field key="dob" dbtype="int" precision="10" phptype="integer" null="false" default="0"> <field key="createdon" dbtype="int" precision="20" phptype="timestamp" null="false" default="0"> <field key="editedon" dbtype="timestamp" phptype="timestamp" null="true" default="NULL"> <field key="createdon" dbtype="datetime" phptype="datetime">
I don't know which would work best for your use case. I'd try the first one first since it's for the modUserProfile object.</field></field></field></field>
<field key="dob" dbtype="int" precision="10" phptype="integer" null="false" default="0" /> <field key="createdon" dbtype="int" precision="20" phptype="timestamp" null="false" default="0" /> <field key="editedon" dbtype="timestamp" phptype="timestamp" null="true" default="NULL" /> <field key="createdon" dbtype="datetime" phptype="datetime" />
>One thing i think about this issue, forgive me if I am out of line or plain wrong, but it seems to me you are trying to use a value within Modx along with values outside of Modx (CE), and this is a source of great trouble and also somehow not aligned well.
Your CE system presumably has a bunch of values for users in it, let's call them values 1-5, but let's recognize that your User system (user values) is/are the real focus. From that angle your user data system looks weird:
UserValue 1 - In CE DB
UserValue 2 - In CE DB
UserValue 3 - In CE DB
UserValue 4 - In Modx>Users>Profile>Path DB
UserValue N - In CE DB
This is the true source of the problem IMHO and can be remedied extremely easily by using a CE value for this data.
I have a tool from my forum days which gets the user creation date and can output, so this task isn't hard (happy to post that if you need), the problem is the intricacies of how Modx parses and manages that string.
<?xml version="1.0" encoding="UTF-8"?> <model package="extendeduser" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="ext_" version="1.0.0"> <!-- extend the modUser class --> <object class="extUser" extends="modUser"> <composite alias="Data" local="id" class="userData" foreign="userdata_id" cardinality="one" owner="local"/> </object> <object class="userData" table="user_data" extends="xPDOSimpleObject"> <field key="userdata_id" dbtype="int" precision="11" phptype="integer" null="false" index="unique" attributes="unsigned"/> <field key="checkin" dbtype="date" precision="100" phptype="date" null="true"/> <field key="checkout" dbtype="date" precision="100" phptype="date" null="true"/> <index alias="userdata_id" name="userdata_id" primary="false" unique="true" type="BTREE"> <column key="userdata_id" length="" collation="A" null="false"/> </index> <aggregate alias="User" class= "modUser" local="userdata_id" foreign="id" cardinality="one" owner="foreign"/> <aggregate alias="Profile" class="modUserProfile" local="userdata_id" foreign="internalKey" cardinality="one" owner="foreign"/> </object> </model>