Hi Folks,
I'm looking to generate a conformation email using Formit (v 2.1.1). As it stands Formit produces an on screen confirmation message but I also want a "thanks" email to be sent.
AFAIK, the only way to do this is create a custom hook that calls a corresponding chunk. Is this correct? I thought perhaps that there might be a way to set a message in the systems settings and call it in the Formit snippet e.g. [[++confirmation_message]] but I can't see a param for such a function in the Formit docs.
My PHP isn't great by any stretch of the imigination but I've come up with the following (which is really just a modification of this excellent tutorial -
http://cipalabs.com/modx/articles/send-a-confirmation-email-with-formit):
<?php
//configuration
$mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
$mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSubject = 'Subject';
$mailReplyTo = $mailFrom;
$message = $modx->getChunk('ConfirmationTpl');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,$mailFrom);
$modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
$modx->mail->set(modMail::MAIL_SENDER,$mailSender);
$modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
$modx->mail->address('to',$mailTo);
$modx->mail->address('reply-to',$mailReplyTo);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
return false;
}
$modx->mail->reset();
return true;
As you can see my 'ConfirmationTpl' chunk will simply contain static text, no dynamic placeholders.
I'm hoping that an experienced eye could look over the above code and see that everything looks correct and that I haven't got anything superfluous in there. All in all, I guess the part of the snippet that is confusing me is the following:
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,$mailFrom);
$modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
$modx->mail->set(modMail::MAIL_SENDER,$mailSender);
$modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
$modx->mail->address('to',$mailTo);
$modx->mail->address('reply-to',$mailReplyTo);
$modx->mail->setHTML(true);
Any explanation of that would be appreciated.
Thanks in advance.
[ed. note: bob-rooney last edited this post 13 years, 8 months ago.]