We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38669
    • 51 Posts
    I have a postHook with the following
    mail('me@mydomain','result', 'user='. $hook->getValue('username') );

    It doesn't work, the email isn't sent.

    However if I use this (remove the API call) it does work - I get the email.

    mail('me@mydomain','result', 'user=' );

    I know I shouldn't tear my hair out over something so simple but...it is so simple.

    What on earth is wrong?
      • 38669
      • 51 Posts
      [UPDATE]

      If I use the generic sample of the docs it does work including both the username and the email. Grrrrrrrrrr. It looks the same...I don't get it...
      $message = 'Hi, a new User signed up: '.$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,'me@mydomain');
      $modx->mail->set(modMail::MAIL_FROM_NAME,'Jerrys Site');
      $modx->mail->set(modMail::MAIL_SENDER,'Jerrys Site');
      $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
      $modx->mail->address('to','me@mydomain');
      $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;
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Try it this way:

        $username = $hook->getValue('username');
        mail('me@mydomain','result',"user=$username");
        
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 38669
          • 51 Posts
          WTF??? That worked sottwell. Thanks so much.

          But why???

          But what I am really trying to do is this
          $email = $hook->getValue('username');
          $hook->setValue('email',$email);


          which I already had and it isn't working. I was using the email to debug. [ed. note: xxxmicrobexxx last edited this post 13 years, 8 months ago.]
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            er... not really sure. At the moment my eyes are too blurry to be able to see it all that well. I just find that trying to jam too much functionality into one line often leads to trouble, maybe because half the time I can't see. Likewise with sql queries - although the Revo way, of course, it to use proper xPDO syntax, no more strings of SQL to get tangled up in. As in the demo version you posted for mail. Your version may be two lines (or one, if you could figure out what the problem with the message parameter is), but not of much use on a server without mail() enabled. Above all, MODx strives for extensibility and portability. Probably not necessary in your case, but a good thing to keep in mind. I definitely need to get off the computer for a while. Good luck!
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org