Sending emails with attachments from Joomla 1.5 components
28.02.2011
The JFactory::getMailer() function allows you to send a message to an email with attachments that are passed to the function in the $files array
- function send($param,$files)
- {
- $dir = JFactory::getConfig()->getValue('tmp_path').'/';
- $mailer =& JFactory::getMailer();
- $mailer->setSender(array($this->config->_get('contact.email'),$_SERVER['HTTP_HOST']));
- $mailer->addRecipient($this->get($param['id'])->name.'get($param['id'])->email.'>');
- $mailer->setSubject('Message with multiple attachments');
- $mailer->setBody('This message must be sent with multiple attachments!');
- foreach($files as $key=>$file)
- {
- move_uploaded_file($file['tmp_name'],$dir.$file['name']);
- $array[$key] = $dir.$file['name'];
- }
- $mailer->addAttachment($array);
- $send =& $mailer->Send();
- foreach($array as $file)
- @unlink($file);
- return ($send) ?true :false;
- }
where,
- $param - An array of objects from which to retrieve the recipient's name and address
- $files - An array of nested files, obtained from the $_FILES superglobal array
- JFactory::getConfig()->getValue('tmp_path').'/' - path to folder where attachments are located
- $this->config->_get('contact.email') - Sender address
- $_SERVER['HTTP_HOST'] - Sender name
- $this->get($param['id'])->name - The recipient's name
- $this->get($param['id'])->email - Recipient's address
SUBSCRIBE TO NEWSLETTER
Last in our blog
Internet Marketing
04.11.2019
Internet Marketing
03.10.2019