<![CDATA[ [Solved] Attach local file, not from form - My Forums]]> https://forums.modx.com/thread/?thread=47642 <![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-496618
[[!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.]]>
blairmcc Apr 30, 2014, 11:51 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-496618
<![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486227 sottwell Dec 31, 2013, 05:58 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486227 <![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486225
M one problem is that I have an auto created file on form submission which puts all the fields into a csv and then saves it to the server with a unique name based on the forename and surname fields and date. ie. alex-mercer-30-12-13.csv and then once this is created I want to attach it to the email. So I can't put the full path to the file in the formit call as the name is dynamic, based on user input. I have put it in the snippet like so:

$scriptProperties['hook']->modx->mail->mailer->AddAttachment($filepath);


But I'm just getting the white screen on submission.

Thanks for any advice]]>
alexmercenary Dec 31, 2013, 05:43 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486225
<![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486223 sottwell Dec 31, 2013, 05:32 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486223 <![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486222 alexmercenary Dec 31, 2013, 05:29 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-486222 <![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-462287
Hi everybody,

It is not working for me ! i have a blank page after the "submit".
this is my formit call :
[[!FormIt?
&attachment=`pdf/file.pdf`
&hooks=`Attachment,email,redirect`
&emailTpl=`devisTpl` 
&emailSubject=`Subject` 
&emailTo=`[email protected]` 
&redirectTo=`6` 
&validate=`nospam:blank,email:required`
]]


here my Snippet:
<?php
if(!empty($attachment)){
  $basepath = $modx->getOption('/var/www/');
  $scriptProperties['hook']->modx->mail->mailer->AddAttachment($basepath.$attachment);
}
return true;


Could someone help me please ?]]>
sironder Apr 09, 2013, 09:51 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-462287
<![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-410141
[[!FormIt?
&attachment=`path_to_file_on_server`
&hooks=`spam,Attachment,email,FormItAutoResponder,redirect`
&emailTpl=`myTpl` etc]]>
renne000 Feb 02, 2012, 03:24 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-410141
<![CDATA[Re: [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-398632 I copied the code exactly as in dj13 example for the snippet.
I checked the output of the path for the attachment and this is 100% correct.

This is my FormIt call:
    [[!FormIt?
        &attachment=`pdf/[[+File]]`
        &hooks=`email,Attachment,redirect`
        &emailTpl=`emailTemplateBrochure`
        &emailTo=`[[+brochureEmail]]`
        &emailBCC=`[email protected]`
        &emailFrom=`[email protected]`
        &emailFromName=`Leenders Makelaardij`
        &emailSubject=`Brochure opgevraagd op de site van Leenders Makelaardij`
        &redirectTo=`28`
        &validate=`brochureNaam:required, brochureEmail:email:required`
        &submitVar=`brochureSubmit`
    ]]

The e-mail is sent and works fine, except for the pdf that is not attached to the e-mail.
Anyone knows what goes wrong here?]]>
Webbiker Nov 01, 2011, 03:04 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-398632
<![CDATA[Re: Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-275342
<?php
if(!empty($attachment)){
  $basepath = $modx->getOption('base_path');
  $scriptProperties['hook']->modx->mail->mailer->AddAttachment($basepath . $attachment);
}
return true;


And call formit like this.
[[!FormIt?
&attachment=`path_to_file_on_server`
&hooks=`spam,email,Attachment,FormItAutoResponder,redirect`
&emailTpl=`myTpl` etc


Important put the Attachment after email in hooks parameter.]]>
dj13 Dec 18, 2010, 01:33 PM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-275342
<![CDATA[ [Solved] Attach local file, not from form]]> https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-275341 How to attach local file from server, not file submited through form?
thx]]>
dj13 Dec 18, 2010, 12:16 AM https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-275341