We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m working on the Revolution version of SPForm. It uses PHPMailer to send the mail and, looking at the core, it looks like PHPMailer still uses the old-style language files.

    Can I count on those remaining where they are for use in SPForm? For that matter, can I count on the PHPMailer phpmailer.class.php file remaining where it is?

    Or should I bite the bullet and use the service:

    $modx->getService('mail', 'mail.modPHPMailer');


    (bearing in mind that I need to set custom headers).
      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
      • 22303 MODX Staff
      • 10,725 Posts
      Yes, we all need to be using and improving the mail service in the reference components.
        • 28215
        • 4,149 Posts
        For an example of how to use it (in the user/create processor):

            $modx->getService('mail', 'mail.modPHPMailer');
            $modx->mail->set(MODX_MAIL_BODY, $message);
            $modx->mail->set(MODX_MAIL_FROM, $modx->config['emailsender']);
            $modx->mail->set(MODX_MAIL_FROM_NAME, $modx->config['site_name']);
            $modx->mail->set(MODX_MAIL_SENDER, $modx->config['emailsender']);
            $modx->mail->set(MODX_MAIL_SUBJECT, $modx->config['emailsubject']);
            $modx->mail->address('to', $email, $ufn);
            $modx->mail->address('reply-to', $modx->config['emailsender']);
            if (!$modx->mail->send()) {
                die($modx->lexicon('error_sending_email_to').$email);
                exit;
            }
            $modx->mail->reset();
        
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 3749
          • 24,544 Posts
          Thanks. smiley I had found that already but didn’t know if it would handle custom headers. I’m guessing it will.

          I didn’t see the mailer lexicon entries in the lexicon. Is there a plan to move them there?

            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
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: BobRay at Oct 02, 2008, 11:53 PM

            I didn’t see the mailer lexicon entries in the lexicon. Is there a plan to move them there?
            Yes; made a sub-task for i18n of modMail at http://svn.modxcms.com/jira/browse/MODX-395
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              And if you need to send mail using SMTP instead of mail()?
                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
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: sottwell at Oct 03, 2008, 01:46 AM

                And if you need to send mail using SMTP instead of mail()?
                Just call...
                <?php
                    $modx->mail->set(MODX_MAIL_ENGINE, 'smtp');
                ?>
                ...and then you can set any of the other smtp constants that need to be set. Here’s the SMTP related constants defined in the modMail class.
                <?php
                define('MODX_MAIL_SMTP_AUTH',       'mail_smtp_auth');
                define('MODX_MAIL_SMTP_HELO',       'mail_smtp_helo');
                define('MODX_MAIL_SMTP_HOSTS',      'mail_smtp_hosts');
                define('MODX_MAIL_SMTP_KEEPALIVE',  'mail_smtp_keepalive');
                define('MODX_MAIL_SMTP_PASS',       'mail_smtp_pass');
                define('MODX_MAIL_SMTP_PORT',       'mail_smtp_port');
                define('MODX_MAIL_SMTP_PREFIX',     'mail_smtp_prefix');
                define('MODX_MAIL_SMTP_SINGLE_TO',  'mail_smtp_single_to');
                define('MODX_MAIL_SMTP_TIMEOUT',    'mail_smtp_timeout');
                define('MODX_MAIL_SMTP_USER',       'mail_smtp_user');
                ?>

                You can also pass in all these attributes when you create the mail service instance...
                <?php
                $modx->getService('mail', 'mail.modPHPMailer', array(
                    MODX_MAIL_SMTP_USER => 'mailuser',
                    MODX_MAIL_SMTP_PASS => 'mailpassword'
                ));
                ?>

                Before beta, I will be adding system settings (defined during setup) for all of these options to be automatically passed in as default attributes for a deployment whenever you call the mail service, but for now, that’s how you can set that manually.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Nice!
                    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
                    • 3749
                    • 24,544 Posts
                    Just having this line alone:

                     $modx->getService('mail', 'mail.modPHPMailer');


                    Generates the fatal error:

                    Fatal error: Cannot redeclare class PHPMailer in C:\xampp\htdocs\MODx097\core\model\modx\mail\phpmailer\class.phpmailer.php on line 29


                    Do I need

                    if (! class_exists() ) somewhere?
                      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
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Not for me, it’s using require_once to include the actual PHPMailer class anyway, so that doesn’t make any sense. Did you name something else PHPMailer? I bet you are including PHPMailer from a file with a different name somewhere...