[[!FileUpload?
&filefields=`1`
&uploadgroups=`Members`
&createpath=`Yes`
&path=`userfiles/[[+modx.user.username]]/`
&maxsize=`1000000
&allowoverwrite=`0`
&dirpermission=`755`
&extensions=`txt,html,htm,xml,zip,gz,rar,z,tgz,tar,pdf,doc,docx,xls,xlsx,ppt,pptx,jpg,jpeg,png,tiff,svg,svgz,gif,psd,ico,bmp,odt,ods,odp,odb,odg,odf`
]]
/* Connected to OnFileManagerUpload Event */
if (! isset($fromfileupload)) {
/* Event not fired by FileUpload snippet */
return '';
}
/** @var $path string */
/** @var $modx modX */
$directory = $path;
foreach($files as $file) {
$name = $file['name'];
$type = $file['type'];
$extension = $file['extension'];
$size = $file['size'];
$tmp_name = $file['tmp_name'];
$error = $file['error'];
/* Your code below. This is an example that writes results to the MODX error log.
* Note: Since $file is an associative array, you can have a Tpl chunk with
* placeholders and use $msg .= $modx->getChunk('MyChunk', $file) for sending
* emails or making your own upload log;
*/
if (empty($error)) {
/* Success */
$modx->log(modX::LOG_LEVEL_ERROR, 'Success: ' . $name);
} else {
/* Failure -- $error contains the error message */
$modx->log(modX::LOG_LEVEL_ERROR, 'ERROR: ' . $name . ' -- ' . $error);
}
}
return '';This question has been answered by deyand. See the first response.
/* Set these variables */ $msg = ''; // The body of the message $from = ''; // Joe Blow <[email protected] $fromName = ''; // name of sender $sender = ''; // Sender's email address $subject = ''; // Email subject $reply = ''; // Reply-to email address /* ************ */ /* Send the message */ $modx->getService('mail', 'mail.modPHPMailer'); $modx->mail->set(modMail::MAIL_BODY, $msg); $modx->mail->set(modMail::MAIL_FROM, $from); $modx->mail->set(modMail::MAIL_FROM_NAME, $fromName); $modx->mail->set(modMail::MAIL_SENDER, $sender); $modx->mail->set(modMail::MAIL_SUBJECT, $subject); $modx->mail->address('to', $email, $name); $modx->mail->address('reply-to',$reply); $modx->mail->setHTML(true); $sent = $modx->mail->send(); $modx->mail->reset();
[2016-04-27 14:30:48] (ERROR @ /xxx/xxx/public_html/subdomain/core/model/modx/mail/modphpmailer.class.php : 152) modPHPMailer does not support unsetting specific addresses. Use reset() to clear all recipients and add back the ones you want to send to. [2016-04-27 14:30:48] (ERROR @ /xxx/xxx/public_html/subdomain/core/cache/includes/elements/modplugin/5.include.cache.php : 77) An error occurred while trying to send the email: You must provide at least one recipient email address. [2016-04-27 14:30:48] (ERROR @ /xxx/xxx/public_html/subdomain/core/cache/includes/elements/modplugin/5.include.cache.php : 84) Success: test.docx
$msg = ''; // The body of the message $from = ''; // Joe Blow <[email protected] $fromName = ''; // name of sender $sender = ''; // Sender's email address $subject = ''; // Email subject $reply = ''; // Reply-to email address
<?php
/**
* Copyright 2015 by Bob Ray
*
* fileupload plugin
*
* FileUpload is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* FileUpload is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* FileUpload; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package fileupload
*
*/
/* Connected to OnFileManagerUpload Event */
if (! isset($fromfileupload)) {
/* Event not fired by FileUpload snippet */
return '';
}
/** @var $path string */
/** @var $modx modX */
$directory = $path;
foreach($files as $file) {
$name = $file['name'];
$type = $file['type'];
$extension = $file['extension'];
$size = $file['size'];
$tmp_name = $file['tmp_name'];
$error = $file['error'];
/* Your code below. This is an example that writes results to the MODX error log.
* Note: Since $file is an associative array, you can have a Tpl chunk with
* placeholders and use $msg .= $modx->getChunk('MyChunk', $file) for sending
* emails or making your own upload log;
*/
//Email
/* Set these variables */
$msg = ''; // The body of the message
$from = ''; // Joe Blow <[email protected]
$fromName = ''; // name of sender
$sender = ''; // Sender's email address
$subject = 'New File Upload'; // Email subject - tried also with empty value
$reply = '[email protected]'; // Reply-to email address - tried also with empty value
/* ************ */
/* Send the message */
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $msg);
$modx->mail->set(modMail::MAIL_FROM, $from);
$modx->mail->set(modMail::MAIL_FROM_NAME, $fromName);
$modx->mail->set(modMail::MAIL_SENDER, $sender);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$modx->mail->address('to', $email, $name);
$modx->mail->address('reply-to',$reply);
$modx->mail->setHTML(true);
$sent = $modx->mail->send();
$modx->mail->reset();
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}else{
$modx->log(modX::LOG_LEVEL_ERROR,'This mail was sent: '.$message);
}
if (empty($error)) {
/* Success */
$modx->log(modX::LOG_LEVEL_ERROR, 'Success: ' . $name);
} else {
/* Failure -- $error contains the error message */
$modx->log(modX::LOG_LEVEL_ERROR, 'ERROR: ' . $name . ' -- ' . $error);
}
}
return '';$msg = ''; // The body of the message, i.e. the text of the message you want to send (with or without placeholders) $from = ''; // Joe Blow <[email protected]>, i.e., your email address $fromName = ''; // name of sender, i.e. Your name $sender = ''; // Sender's email address, use the same thing as $from.
... //Email /* Set these variables */ $msg = 'A User uploaded a file to his profile.'; // The body of the message, i.e. the text of the message you want to send (with or without placeholders) $from = '[email protected]'; // Joe Blow <[email protected]>, i.e., your email address $fromName = 'Admin'; // name of sender, i.e. Your name $sender = 'Admin'; // Sender's email address, use the same thing as $from. $subject = 'New File Upload'; // Email subject $reply = '[email protected]'; // Reply-to email address /* ************ */ ...