Hi, folks!
I wrote a plugin with OnDocFormSave event which, when manager saves a resource, sends mail with some data about these changes to the registered users on my site. The problem is that I also need to attach a file to this mail. For example, this file is placed in 'assets/files' directory on my server.
I tried to solve the problem using native modPHPMailer and then modSwiftMailer (from repository). So the thing is that modPHPMailer succefully sends mail to the user's mailbox but without any attached files, even if I add $modx->mail->attach('assets/files/file.txt') to modPHPMailer call.
The even more strange thing happens with modSwiftMailer. It sends mail too, but when I add the above piece of code ($modx->mail->attach) to it some internal "Please Wait..." starts to load in manager while tryin' to save resource.
Below are two pieces of code in my plugin.
modPHPMailer call
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,'Message text');
$modx->mail->set(modMail::MAIL_FROM,'[email protected]');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Site.com');
$modx->mail->set(modMail::MAIL_SENDER,'Site.com admin');
$modx->mail->set(modMail::MAIL_SUBJECT,'Message subject');
$modx->mail->address('to','[email protected]');
$modx->mail->address('reply-to','[email protected]');
$modx->mail->attach('assets/files/file.txt');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
modSwiftMailer call
$modx->getService('mail', 'mail.modSwiftMailer');
$modx->mail->address('to', '[email protected]', 'Recipient');
$modx->mail->address('sender', '[email protected]');
$modx->mail->replyto('[email protected]');
$modx->mail->subject('Site.com');
$modx->mail->body('Message text');
$modx->mail->attach('assets/files/file.txt');
$modx->mail->send();
I would appreciate any possible help from memebers of our great community