We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10190
    • 187 Posts
    Hi,

    hope this is right place for this question:

    Every time I try to send a webuser or manager’s password via email I get the error in a popup:

    Error send mail to

    The email adress is not shown, neither is the email being sent.

    What do I do wrong?

    Email works from the commandline with mail, phpinfo shows correct sendmail_path and sendmail_from.

    Any clues?

    Cheers
    Frisco




      • 9207 ☆ A M B ☆
      • 2,475 Posts
      How, exactly are you trying to send the email? Are you using a Snippet, or are you trying to send it manually from the manager?

      Another good diagnostic trick to create a simple Snippet that sends an email:
      <?php
      $txt = "First line of text\nSecond line of text";
      
      // Use wordwrap() if lines are longer than 70 characters
      $txt = wordwrap($txt,70);
      
      // Send email
      mail("[email protected]","My subject",$txt);
      ?>

      Example is from: http://www.w3schools.com/PHP/func_mail_mail.asp

      Reference that Snippet on a page and see if you receive emails when you hit the page. If you don’t, it’s possible that your server isn’t configured correctly or your hosting provider is filtering emails (as spam, probably).

      What version of MODx and PHP are you using?
        • 20413
        • 2,877 Posts
        I know that versions before 0962 had many bugs related to e-mails sent from MODx manager.
        E.g. http://modxcms.com/forums/index.php/topic,28479.msg173742.html#msg173742

        So yes upgrade if that’s an option.
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 10190
          • 187 Posts
          Dear Everett, dear mrhaw,

          thanks alot for your help!

          Everett, I use the manager, security::webuser and try to send the password via email to a newly added webuser, or, for reasons of testing, to existing webusers (with my email adress) after changing the password.

          This is a default functionality.

          I tried your snippet as well, but nothing happens, and I can’t see anything in the logs.

          I have a vserver with root access, and mail should be configured correct - i.e. cron sends emails to me every night in case of problems or notifications.

          mrhaw, I use 0.9.6.3, so unfortunatly upgrading is no option as long as no new version is released - or revolutions becomes stable wink

          I suppose that there could be a problem with user www-data sending mail, shell users like root or myself are configured correctly, I’ve tested that.

          I use msmtp instead of sendmail - it want’s it’s config in ~/.msmtprc. I copied the working config to /etc/msmtprc and put php.ini to

          sendmail_from [email protected]
          sendmail_path /usr/bin/msmtp -t -i -C /etc/msmtprc
          (output from phpinfo()

          Nevertheless, no emails are sent.

          Any clues?
          Cheers
          Frisco
            • 3749
            • 24,544 Posts
            I’m no mail expert, but I think that by default MODx (and most MODx snippets) use the PHP mail() function to send mail. That’s not the same as sendmail.

            If Everett’s snippet didn’t work, the host probably has mail() turned off.

            There’s probably a way to configure the Manager to use SMTP, but I’ve never done it.
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              What the php mail() function uses depends on the php configuration.
              http://il.php.net/manual/en/mail.configuration.php
                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
                • 10190
                • 187 Posts
                Hi sottwell,

                that’s exactly how I understood it. Thus I put the following config in /etc/php5/cgi/php.ini:

                [mail function]
                ; For Win32 only.
                SMTP = smtp.gmail.com
                smtp_port = 587

                ; For Win32 only.
                sendmail_from = [email protected]

                ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
                sendmail_path = /usr/bin/msmtp -t -i -C /etc/msmtprc

                I tried using the interactive mode with php-cgi, but this doesn’t change a thing - no errors, but no mail sent - and I have error logging on (display and file).

                Maybe I need php5-net-mail or something similar?

                I hacked the mail function used by modx to display the content of the vars used to send the mail, they all look fine - it’s just that php-cgi doesn’t send the mail.

                I’m using:
                PHP 5.2.9-4 with Suhosin-Patch 0.9.7 (cgi-fcgi) (built: May 18 2009 20:06:33)

                together with lighttpd. As I wrote above, phpinfo shows the correct mail config.

                I’m running out of ideas, and google doesn’t help me either - everything’s seems to be configured right, and sending mail without php works fine:

                su www-data
                $ mail [email protected]
                Subject: test
                test
                Cc: send-mail: kann Log Information nicht in /var/log/msmtp.log schreiben: kann Datei nicht öffnen: Keine Berechtigung
                send-mail: Log Information war: host=smtp.gmail.com tls=on auth=on [email protected] [email protected] [email protected] mailsize=52 smtpstatus=250 smtpmsg=’250 2.0.0 OK 1245352161 v32sm1277380wah.48’ exitcode=EX_OK
                frisco:/root$

                (The error message is only about ww-data not being able to write to msmtp.log, which I will change now smiley

                Cheers
                Frisco
                  • 3749
                  • 24,544 Posts
                  To send from GMail with SMTP I think you’ll need to set it to authenticate and add a username and password.

                  I believe GMail requires an SSL (TLS) connection as well.

                  GMail will also rewrite your from address in an annoying way.

                  Here’s a script for PhpMailer that might help:

                  http://www.xanda.org/index.php?page=use-gmail-smtp-to-send-mail-in-php
                    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
                    • 10190
                    • 187 Posts
                    BobRay,

                    your perfectly right about gmail auth. This is normally handled by the config file .msmtprc in the users home dir or by /etc/msmtprc (the file I refer to in php.ini via: sendmail_path = /usr/bin/msmtp -t -i -C /etc/msmtprc).

                    This config works, as it is used when I send mail via the command mail from bash.

                    I tried your recommended PHPMailer with the same config options (as far as I could set them, ’cause there’s nothing for a tls certificate), but it says:

                    SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

                    which might come from the missing tls certificate.

                    Here is what I use with msmtp and PHPMailer:

                    $ cat /home/frisco/.msmtprc
                    account default
                    host smtp.gmail.com
                    port 587
                    timeout 30
                    auth on
                    user [email protected]
                    password ******
                    auto_from off
                    from [email protected]
                    maildomain domain.com
                    tls on
                    tls_starttls on
                    tls_trust_file /etc/ssl/certs/ca-certificates.crt
                    logfile /var/log/msmtp.log
                    


                    <?php                                                                                                            
                    include("class.phpmailer.php");                                                                                  
                    $mail = new PHPMailer();                                                                                         
                    $mail->IsSMTP();                                                                                                 
                    $mail->SMTPAuth   = true; // enable SMTP authentication                                                          
                    $mail->SMTPSecure = "ssl"; // use ssl                                                                            
                    $mail->Host = "smtp.gmail.com"; // GMAIL's SMTP server                                                           
                    $mail->Port  = 587; // SMTP port used by GMAIL server                                                            
                    $mail->Username   = "[email protected]"; // GMAIL username                                             
                    $mail->Password   = "******"; // GMAIL password                                                                
                    $mail->AddReplyTo("[email protected]","Firstname Lastname"); // Reply email address                         
                    $mail->From = "[email protected]";                                                                     
                    $mail->FromName = "Firstname Lastname"; // Name to appear once the email is sent                                      
                    $mail->Subject = "Subject of the email"; // Email's subject                                                      
                    $mail->Body = "Hello World,<br />This is the HTML BODY<br />"; //HTML Body                                       
                    //$mail->AltBody = "This is a test email"; // optional, comment out and test                                     
                    $mail->WordWrap = 50; // set word wrap
                    //$mail->MsgHTML($body); // [optional] Send body email as HTML
                    $mail->AddAddress("[email protected]", "company");  // email address of recipient
                    //$mail->AddAttachment("files/files.zip"); // [optional] attachment
                    //$mail->IsHTML(true); // [optional] send as HTML
                    if(!$mail->Send())
                    echo "Mailer Error: " . $mail->ErrorInfo;
                    else
                    echo "Message sent!";
                    ?>
                    


                    Any more clues?
                    Cheers
                    Frisco
                      • 3749
                      • 24,544 Posts
                      $mail->SMTPDebug = 4; wink

                      (Try 2 first, that may be enough.)
                        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