This snippet is for use with MODX Revolution. QuickEmail can be used to send email from inside another snippet, but its primary use is to see if your email is working, and if not, to help diagnose and solve email problems.
Go to Extras -> Installer on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository. Put QuickEmail in the search box and press Enter. Click on the "Download" button, and when it changes to "Downloaded," click on the "Finish" button. That should bring you back to your Package Management grid. Right click on QuickEmail and select "Install Package." The QuickEmail snippet should now be installed.
This couldn't be much simpler. Create a document in the Manager and put the following code in the Resource Content field:
[[!QuickEmail]]
When you view the document in the front end, you should receive an email at the address you specified when you installed MODX. You can go to System -> System Settings the top menu and put emailsender in the search filter to check that address. If you don't receive an email, Change the snippet tag to look like this:
[[!QuickEmail? &debug=`1`]]
Try viewing the document again and look for an error message near the bottom of the screen.
If you see a message that says, "Could not instantiate mail function," it usually means that either your host has the mail() function turned off (many do) or that you are using a localhost install and there is no working mail server. In that case, one option is to use the MODX SMTP Systems Settings so that MODX will send the mail from an SMTP server (e.g., Gmail) where you have an account.
If you have two-factor authentication on your Google account, you may need an app password to use your account to send SMTP email. See this page for more information.
Go to System -> System Settings and type SMTP in the search filter, then click on the grid. Set the SMTP settings to the appropriate values for your SMTP account. The following settings will work for Gmail:
SMTP Authentication: Yes SMTP Connection Prefix: tls SMTP Hosts: smtp.gmail.com SMTP Password: yourGmailPassword SMTP Port: 465 SMTP User: yourGmailUsername Use SMTP: Yes
Note that Gmail will change all the email from addresses to match your Gmail account and any settings you use in the tag will be ignored. You can have a separate account in Gmail for sending email from your site if you wish.
Once you have set the SMTP settings, try viewing your page again. If there are SMTP errors, you will see a detailed account of the Server interaction. Look for any errors and correct the SMTP settings accordingly. A timeout usually means a problem with the port number or failure to set the SMTP prefix. Failure to connect to the host, usually means the SMTP hosts is incorrect or the SMTP prefix is not set correctly. If you've forgotten to set the SMTP authentication, it will remind you. If there is a problem with authentication, either the SMTP username or the SMTP password are incorrect — there's no way to tell which one is the problem.
You can use the following code to send email from inside another snippet, although it is just as easy to use the MODX mailer. The MODX mailer is also more efficient, because QuickEmail will do a bunch of processing and then call the MODX mailer. Don't try any of the code below until you've made sure your mail system is working using the method described above.
$props = array( 'debug' => '0', 'hideOutput' => '0', 'message' => 'Some Message', 'subject' => 'Some Subject', 'to' => 'someone@somewhere.com', 'fromName' => 'Some Name', 'emailSender' => 'someone@somewhere.com', 'replyTo' => 'someone@somewhere.com', 'html' => '1', 'failureMessage' => '<br /><h3 style="color:red">Mail Failed</h3>', 'successMessage' => '<br /><h3 style ="color:green">Mail reported successful</h3>', 'errorHeader' => '<br />Mail error:', 'smtpErrorHeader' => '<br />SMTP server report:', ); $output = $modx->runSnippet('QuickEmail',$props); return $output;
Once you have things working, you may want to set 'hideOutput' to '1'. As an alternative, you can modify the $output variable before returning it. If 'hideOutput' is set to '1', there will be no visible output at all from the snippet — it will just send the email.
All of the properties are optional and have reasonable defaults so try just setting 'message', 'subject', and 'to', and see what you get.
Since I mentioned it above, here is how you send email using the MODX built-in email function:
$modx->getService('mail', 'mail.modPHPMailer'); $modx->mail->set(modMail::MAIL_BODY, 'Some message'); $modx->mail->set(modMail::MAIL_FROM, 'someone@somewhere.com'); $modx->mail->set(modMail::MAIL_FROM_NAME, 'Your Name'); $modx->mail->set(modMail::MAIL_SENDER, 'you@yourdomain.com'); $modx->mail->set(modMail::MAIL_SUBJECT, 'Some Subject'); $modx->mail->address('to', 'somone@somewhere.com', 'UserName'); $modx->mail->address('reply-to', 'you@yourdomain.com'); $modx->mail->setHTML(true); $sent = $modx->mail->send(); if ($sent) { $output = 'Mail Sent'; } else { $output = 'Mail Not Sent'; } return $output;