I realize I'm once again resurrecting a long-dead thread, but I've spent several hours being extremely frustrated that there didn't seem to be an actual answer to this problem. Like sironder and alexmercenary, I was getting a blank white page when I attempted to implement the above solutions for emailing a local file using a custom Formit hook. Here's my simplified FormIt call (I'll use '***' throughout to designate redacted information):
[[!FormIt?
&hooks=`FormItAttach,email`
&emailTpl=`emailTpl`
&emailSubject=`***`
&emailTo=`***@***.***`
]]
And here's a simplified version of my original "FormItAttach" snippet:
$attachment = '/tmp/***.***';
$scriptProperties['hook']->modx->mail->mailer->AddAttachment($attachment);
return true;
When I would submit my form, I would get a blank white page. After making sure everything was as it should be, I checked PHP's error log. Here's what I found:
[Wed Apr 30 10:56:35 2014] [error] [client ***] PHP Fatal error: Call to a member function AddAttachment() on a non-object in /***/core/cache/includes/elements/modsnippet/120.include.cache.php on line 31, referer: http://***/
This led me on a wild and frustrating Google-chase. Eventually I stumbled upon the documentation for modMail (
http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/modx-services/modmail). In the provided example, they used the following
before they started creating an email:
$modx->getService('mail', 'mail.modPHPMailer');
Curious, I modified my "FormItAttach" snippet to the following:
$attachment = '/tmp/***.***';
$hook->modx->getService('mail', 'mail.modPHPMailer');
$hook->modx->mail->mailer->AddAttachment($attachment);
return true;
And, what do you know, it worked. I can't really tell you exactly why it worked—or why the previous solutions worked for some people, but not others, but
this worked for me, and if I can save someone else a few frustrating hours of fruitless Googling, so be it.
That is all.