/** * Return all mail attachments for given mail id * * @param int $mailId * @return Gpf_Data_RecordSet */ public static function getMailAttachments($mailId) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add('f.*'); $select->select->add('ma.is_included_image', 'is_included_image'); $select->from->add(Gpf_Db_Table_MailAttachments::getName(), 'ma'); $select->from->addInnerJoin(Gpf_Db_Table_Files::getName(), 'f', 'f.fileid=ma.fileid'); $select->where->add('mailid', '=', $mailId); return $select->getAllRows(); }
/** * Try to send Outbox entry * * @param Gpf_Data_Record $mail */ private function sendMail(Gpf_Data_Record $outbox) { //build mail $mail = new Gpf_Mail(); //set transfer method (smtp or mail) if ($outbox->get('use_smtp') == Gpf::YES) { if ($outbox->get('smtp_ssl') == Gpf::YES) { $this->checkSSL(); } $mail->setTransferMethod('smtp'); $mail->setTransferParams(array('host' => $outbox->get('smtp_server'), 'port' => $outbox->get('smtp_port'), 'auth' => $outbox->get('smtp_auth') == Gpf::YES ? strlen($outbox->get('smtp_auth_method')) ? $outbox->get('smtp_auth_method') : true : false, 'username' => $outbox->get('smtp_username'), 'password' => $outbox->get('smtp_password'), 'localhost' => 'localhost', 'timeout' => 30, 'verp' => false, 'debug' => false, 'persist' => false)); } else { $mail->setTransferMethod('mail'); $mail->setTransferParams(null); } $mail->setRecipients($outbox->get('to_recipients')); $mail->setCcRecipients($outbox->get('cc_recipients')); $mail->setBccRecipients($outbox->get('bcc_recipients')); $mail->setFullFromAddress($outbox->get('from_mail')); $mail->setHtmlBody($outbox->get('body_html')); $mail->setTxtBody($outbox->get('body_text')); if ($outbox->get('reply_to') != '') { $mail->setFrom('', $outbox->get('from_mail')); $mail->setReplyTo($outbox->get('reply_to')); } else { $mail->setReplyTo($outbox->get('from_mail')); } $mail->setSubject($outbox->get('subject')); $mail->setUserAgent('Quality Unit Mail Services'); //add attachments and inner images $attachments = Gpf_Db_Table_MailAttachments::getMailAttachments($outbox->get('mailid')); foreach ($attachments as $attachment) { if ($attachment->get('is_included_image') == Gpf::YES) { $mail->addImage($attachment->get('filename'), Gpf_Db_Table_FileContents::getFileContent($attachment->get('fileid')), $attachment->get('filetype')); } else { $mail->addAttachment($attachment->get('filename'), $attachment->get('filetype'), Gpf_Db_Table_FileContents::getFileContent($attachment->get('fileid'))); } } $mail->send(); return true; }
protected function createMailAttachments(Gpf_Db_MailTemplate $template, Gpf_Db_Mail $mail) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->add('fileid', 'fileid'); $select->select->addConstant($mail->get('mailid'), 'mailid'); $select->select->add('is_included_image', 'is_included_image'); $select->from->add(Gpf_Db_Table_MailTemplateAttachments::getName()); $select->where->add('templateid', '=', $template->get('templateid')); $insert = new Gpf_SqlBuilder_InsertBuilder(); $insert->setTable(Gpf_Db_Table_MailAttachments::getInstance()); $insert->fromSelect($select); $insert->execute(); }
function init() { $this->setTable(Gpf_Db_Table_MailAttachments::getInstance()); parent::init(); }
/** * @return Gpf_DbEngine_Row_Collection<Gpf_Db_File> */ public function getAttachements() { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Gpf_Db_Table_Files::getInstance(), 'f'); $select->from->add(Gpf_Db_Table_MailAttachments::getName(), 'ma'); $select->from->addInnerJoin(Gpf_Db_Table_Files::getName(), 'f', 'ma.' . Gpf_Db_Table_MailAttachments::FILE_ID . ' = f.' . Gpf_Db_Table_Files::ID); $select->where->add("ma." . Gpf_Db_Table_Mails::ID, "=", $this->getId()); $file = new Gpf_Db_File(); return $file->loadCollectionFromRecordset($select->getAllRows()); }