[[!Personalize? &yesChunk=`download` &noChunk=`register`]]
<div class="clear"></div> <h3 class="downloads">File no.1</h3> <a class="btn_download" href="assets/files/file1.pdf">Download</a> <div class="clear"></div> <h3 class="downloads">File no.2</h3> <a class="btn_download" href="assets/files/file2.pdf">Download</a>
This question has been answered by multiple community members. See the first response.
<a href="mysite.com/downloads/abcde.html?file=file1.pdf" &target="_blank">Download file1.pdf</a>
$username = $modx->getLoginUserName();
$file = $_GET['file']; // Make sure to validate and sanitize this before using it!!!
// something like this may be all you need
$filename = preg_replace('/[^0-9a-z\.\_\-]/i','',$file)
if(file_exists('assets/files/pdfs/' . $filename)) {
$msg = "User $username downloaded $filename";
...
//send the mail via your preferred mailing method
...
// redirect the user to the file itself for downloading
$modx -> sendRedirect('assets/files/pdfs/'. $filename);
}
// just quietly die if the sanitized file doesn't exist (perhaps somebody tried to substitute a malicious filename)
return;
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, 'Some message');
$modx->mail->set(modMail::MAIL_FROM, '[email protected]');
$modx->mail->set(modMail::MAIL_FROM_NAME, 'Your Name');
$modx->mail->set(modMail::MAIL_SENDER, '[email protected]');
$modx->mail->set(modMail::MAIL_SUBJECT, 'Some Subject');
$modx->mail->address('to', '[email protected]', 'UserName');
$modx->mail->address('reply-to', '[email protected]');
$modx->mail->setHTML(true);
$sent = $modx->mail->send();
if ($sent) {
/* mail sent successfully */
/* remove this next line when things are working */
$modx->log(modX::LOG_LEVEL_ERROR, 'Sent mail successfully to: ' . $username);
} else {
/* mail failed */
$modx->log(modX::LOG_LEVEL_ERROR, 'Failed sending mail to: ' . $username);
}
return $output;<a href="http://www.mywebsite.com/index.php?id=41&file=file1.pdf">File No.1</a>
[[Sendinfo? &fullName='fullname' &file=`file1.pdf`]]
if ($modx->user->hasSessionContext($modx->context->get('key')) ) {
$output = $modx->getChunk($yesChunk);
if (isset($ph)) {
if ($fullName) {
$profile = $modx->user->getOne('Profile');
$modx->setPlaceholder($ph, $profile->get('fullname'));
} else {
$modx->setPlaceholder($ph, $modx->user->get('username'));
}
}
} else {
$output = $modx->getChunk($noChunk);
}<a href="[[~41? &file=`file1.pdf`]]">File</a>

))))