public function emailCompanyWithAttachments($toAddress, $content, $filename)
 {
     $emailer = new Application_Core_Mail();
     $emailer->setTo($toAddress, $toAddress);
     $emailer->setFrom('*****@*****.**', '*****@*****.**');
     $emailer->setSubject('Company Application');
     $emailer->setBodyText($content);
     // Attach all files from detailAttachments
     $emailer->addAttachment($filename, substr($filename, strrpos($filename, '/') + 1));
     // Send and set returnval
     $success = $emailer->send();
     if ($success) {
         $returnVal = true;
     } else {
         $returnVal = false;
     }
     return $returnVal;
 }
Example #2
0
 /**
  * Opens a PDF from local storage, populates it with agent details (if
  * needed) and outputs it to either browser or by e-mail.
  *
  * @param string $formName The name of the PDF form, or 'all' for all by e-mail.
  * @param mixed $asn Agent scheme number of agent whose details are to be inserted.
  * @param int $agentUserId Optional user ID - needed for e-mailing forms.
  * @param string $destination Optional output mechanism, if set should be 'browser' or not 'browser'.
  * @param mixed $refno Optional reference number, for a special case PDF that requires applicant data injection.
  */
 public function populateAndOuput($formName, $asn, $agentUserId = null, $destination = 'browser', $refno = null)
 {
     $attachmentList = array();
     switch ($formName) {
         // Forms that require agent details to be injected
         case 'Agent-Company':
         case 'Agent-Guarantor':
         case 'Agent-Individual':
         case 'Agent-Student-guarantor':
         case 'Agent-Unemployed-guarantor':
             // Instantiate agent manager and fetch agent details
             $agentManager = new Manager_Core_Agent();
             $agent = $agentManager->getAgent($asn);
             // Shove agent details through form
             $this->setForm($formName);
             $this->agentPopulate($agent);
             // For "Print Guarantor Form" from ref summary screen:
             if (!is_null($refno)) {
                 // Fetch reference by refno using the Referencing MUNT Manager class
                 $refMuntManager = new Manager_ReferencingLegacy_Munt();
                 $reference = $refMuntManager->getReference($refno);
                 // For safety, ensure reference belongs to this ASN before injecting applicant details
                 if ($reference->customer->customerId == $asn) {
                     $this->applicantPopulate($reference);
                 }
             }
             if ($destination == 'browser') {
                 $this->output('browser');
             } else {
                 $attachmentList[$formName] = $this->output('file');
             }
             break;
             // Forms that are a pass-through
         // Forms that are a pass-through
         case 'Tenant-Declaration':
         case 'Guarantor-Declaration':
             $this->setForm($formName);
             if ($destination == 'browser') {
                 $this->output('browser');
             } else {
                 $attachmentList[$formName] = $this->output('file');
             }
             break;
             // Send all forms - by e-mail only
         // Send all forms - by e-mail only
         case 'all':
             // Instantiate agent manager and fetch agent details
             $agentManager = new Manager_Core_Agent();
             $agent = $agentManager->getAgent($asn);
             // Generate those needing agent data merged in
             foreach (array('Agent-Company', 'Agent-Guarantor', 'Agent-Individual', 'Agent-Student-guarantor', 'Agent-Unemployed-guarantor') as $thisFormName) {
                 $this->setForm($thisFormName);
                 $this->agentPopulate($agent);
                 $attachmentList[$thisFormName] = $this->output('file');
             }
             // Generate straight throughs
             foreach (array('Tenant-Declaration', 'Guarantor-Declaration') as $thisFormName) {
                 $this->setForm($thisFormName);
                 $attachmentList[$thisFormName] = $this->output('file');
             }
             break;
     }
     // If there are attachments, this is/these are to be sent by e-mail
     if (count($attachmentList) > 0) {
         // Instantiate agent user manager to get name and e-mail address
         $agentUserManager = new Manager_Core_Agent_User();
         $agentUser = $agentUserManager->getUser($agentUserId);
         // Generate e-mail
         $mailer = new Application_Core_Mail();
         $mailer->setTo($agentUser->email->emailAddress, $agentUser->name);
         // TODO: Parameterise:
         $mailer->setFrom('*****@*****.**', 'HomeLet Referencing');
         $mailer->setSubject('HomeLet Referencing Application Form');
         $mailer->setBodyText('Please find your HomeLet referencing application forms attached.');
         foreach ($attachmentList as $name => $location) {
             $mailer->addAttachment($location, "{$name}.pdf");
         }
         $mailer->send();
         // Garbage collection
         $this->garbageCollect($attachmentList);
     }
 }
 public function applyAction()
 {
     $this->view->pageTitle = 'Careers';
     if ($this->getRequest()->isPost()) {
         // Handle the cv file and form data
         $filters = array('name' => 'StringTrim', 'tel' => 'StringTrim', 'email' => 'StringTrim', 'enquiry' => 'StringTrim');
         $validators = array('name' => array('NotEmpty', 'messages' => 'Please enter your name'), 'tel' => array('NotEmpty', 'messages' => 'Please enter your telephone number'), 'email' => array('NotEmpty', 'messages' => 'Please enter your email address'), 'enquiry' => array('NotEmpty', 'messages' => 'Please tell us why this position interests you'));
         $input = new Zend_Filter_Input($filters, $validators, $_POST);
         if ($input->isValid()) {
             $upload = new Zend_File_Transfer();
             // Make sure the file is actually a document
             $upload->clearValidators();
             $upload->setOptions(array('ignoreNoFile' => true));
             //$upload->addValidator('MimeType', false, array('application/msword', 'application/pdf', 'application/rtf', 'text/plain'));
             if ($upload->isValid()) {
                 $params = Zend_Registry::get('params');
                 $uploadPath = $params->cms->fileUploadPath;
                 $upload->setDestination($uploadPath);
                 $upload->receive();
                 $fileInfo = $upload->getFileInfo();
                 $emailer = new Application_Core_Mail();
                 $emailer->setTo($params->email->careers, 'HomeLet');
                 $emailer->setFrom($input->email, $input->name);
                 $emailer->setSubject('HomeLet - Job Application (' . $input->position . ')');
                 $bodyHtml = 'Position : ' . $input->position . '<br />';
                 $bodyHtml .= 'Name : ' . $input->name . '<br />';
                 $bodyHtml .= 'Email : ' . $input->email . '<br />';
                 $bodyHtml .= 'Tel : ' . $input->tel . '<br />';
                 $bodyHtml .= 'Enquiry : <pre>' . $input->enquiry . '</pre><br />';
                 if ($fileInfo['cv_file']['type'] !== null) {
                     $emailer->addAttachment($fileInfo['cv_file']['destination'] . '/' . $fileInfo['cv_file']['name'], $fileInfo['cv_file']['name']);
                 }
                 $emailer->setBodyHtml($bodyHtml);
                 if ($emailer->send()) {
                     $this->_helper->redirector('thanks', 'careers');
                 } else {
                 }
             } else {
                 // Invalid file type
                 $this->view->errors = array('cv_file' => 'Invalid file type');
                 $this->view->name = $input->name;
                 $this->view->tel = $input->tel;
                 $this->view->email = $input->email;
                 $this->view->enquiry = $input->enquiry;
             }
         } else {
             // Invalid form data
             $this->view->errors = $input->getMessages();
             $this->view->name = $input->name;
             $this->view->tel = $input->tel;
             $this->view->email = $input->email;
             $this->view->enquiry = $input->enquiry;
         }
     }
     $careerUrl = $this->getRequest()->getParam('careerID');
     $careerID = substr($careerUrl, 0, strpos($careerUrl, '-'));
     $careers = new Datasource_Cms_Careers();
     $career = $careers->getById($careerID);
     $this->view->title = $career['title'];
     $this->view->id = $career['id'];
 }
Example #4
0
 /**
  * Sends an email to 'The Assessor' who responsible for processing details provided by the reference subject.
  *
  * Provides support for attachments, automatically including any uploaded by the
  * reference subject.
  * 
  * @param mixed $enquiryId
  * The unique Enquiry identifier (internal or external). May be integer or string.
  *
  * @param string $content
  * The content of the message sent by the reference subject.
  *
  * @return boolean
  * Returns true on successful send, false otherwise.
  */
 public function notifyAssessorWithAttachments($content)
 {
     $emailer = new Application_Core_Mail();
     $emailer->setTo('*****@*****.**', 'Applicant Enquiries');
     $emailer->setFrom('*****@*****.**', 'Tenant Tracker');
     $emailer->setSubject('Tenant Application Tracker');
     $emailer->setBodyText($content);
     // Attach all files from detailAttachments
     foreach (array_keys($this->detailAttachments($this->_reference->internalId)) as $filename) {
         $emailer->addAttachment($filename, substr($filename, strrpos($filename, '/') + 1));
     }
     // Send and set returnval
     $success = $emailer->send();
     if ($success) {
         $returnVal = true;
     } else {
         $returnVal = false;
     }
     return $returnVal;
 }
Example #5
0
 /**
  * Sends an email to 'Claim Handler' with attachments
  *
  * @param int $claimRefNo
  * @param String $content
  * @param int $agentSchemeNumber
  * @param int $attachment
  * @param String $agentEmail
  * Provides support for attachments, automatically including any uploaded by the
  * reference subject.
  *
  * @return boolean
  * Returns true on successful send, false otherwise.
  */
 public function notifyEmailHandlerWithAttachments($claimRefNo, $content, $agentSchemeNumber, $attachment, $agentEmail)
 {
     // Fetch params from registry for default From address
     $this->_params = Zend_Registry::get('params');
     $emailer = new Application_Core_Mail();
     $keyHouseClaimManager = new Datasource_Insurance_KeyHouse_Claim();
     $keyHouseClaimManager = $keyHouseClaimManager->getClaim($claimRefNo, $agentSchemeNumber);
     $getClaimHandler = $keyHouseClaimManager[0]['ClaimsHandlerEmail'];
     $emailer->setTo($getClaimHandler, 'KHDBView');
     $emailer->setFrom($this->_params->homelet->defaultEmailAddress, 'Online Claims');
     $emailer->setSubject('ASN:' . $agentSchemeNumber . ';' . 'Claim Ref:' . $claimRefNo);
     $setBodyContent = '';
     $setBodyContent .= "ASN: {$agentSchemeNumber} \r\n\r\n";
     $setBodyContent .= "Claim Ref No: {$claimRefNo} \r\n\r\n";
     $setBodyContent .= "Contact e-mail: {$agentEmail}\r\n\r\n";
     $setBodyContent .= $content;
     $emailer->setBodyText($setBodyContent);
     $claimDir = explode('/', $claimRefNo);
     if ($attachment == 1) {
         // Attach all files from detailAttachments
         foreach (array_keys($this->detailAttachments($claimDir[1], $agentSchemeNumber)) as $filename) {
             $emailer->addAttachment($filename, substr($filename, strrpos($filename, '/') + 1));
         }
     }
     // Send and set returnval
     $success = $emailer->send();
     if ($success) {
         $returnVal = true;
     } else {
         $returnVal = false;
     }
     return $returnVal;
 }
 /**
  * Handles display, validation and sending of company application form
  */
 public function companyApplicationAction()
 {
     // Instantiate form
     $pageForm = new Connect_Form_ReferencingCompanyApplication();
     $request = $this->getRequest();
     if ($request->isPost()) {
         // We have post data from the company app form - so attempt
         //   validation
         if ($pageForm->isValid($request->getPost())) {
             // Form valid!
             // Format text data ready for e-mail
             $agentManager = new Manager_Core_Agent($this->_agentSchemeNumber);
             $address = $agentManager->getPhysicalAddressByCategory(Model_Core_Agent_ContactMapCategory::OFFICE);
             $agentAddress = $address->toString();
             switch ($request->getParam('how_rg_offered')) {
                 case 1:
                     $howOffered = "Free of charge";
                     break;
                 case 2:
                     $howOffered = "Included in Management Fees";
                     break;
                 case 3:
                     $howOffered = "Separate charge for Rent Guarantee to the landlord";
                     break;
                 case 4:
                     $howOffered = "Referening Only";
                     break;
             }
             switch ($request->getParam('property_managed')) {
                 case 1:
                     $howManaged = "Let Only";
                     break;
                 case 2:
                     $howManaged = "Managed";
                     break;
                 case 3:
                     $howManaged = "Rent Collect";
                     break;
             }
             //Convert the product id into a product name
             $cleanData = $pageForm->getValues();
             $productManager = new Manager_Referencing_Product();
             $product = $productManager->getById($cleanData['subform_product']['product']);
             $productName = empty($product->name) ? '' : $product->name;
             $message = 'Agent Scheme Number: ' . $this->_agentSchemeNumber . "\n" . 'Agent Name: ' . $this->_agentObj->name . "\n" . 'Agent address: ' . $agentAddress . "\n\n" . 'Product: ' . $product->name . "\n" . "\nProperty To Let:\n" . 'Address: ' . $request->getParam('property_address') . "\n" . 'Postcode: ' . $request->getParam('property_postcode') . "\n" . 'Managed Property: ' . $howManaged . "\n" . 'How is Rent Guarantee offered to the landlord: ' . $howOffered . "\n" . 'Total Rent: ' . $request->getParam('tenant_renttotal') . "\n" . 'Rent Share: ' . $request->getParam('tenant_rentshare') . "\n" . 'Tenancy Term: ' . $request->getParam('tenant_term') . "\n" . 'Start Date: ' . $request->getParam('tenant_startdate') . "\n" . 'Total Reference Count: ' . $request->getParam('tenant_number') . "\n" . "\nLandlord Details: \n" . 'First Name: ' . $request->getParam('landlord_firstname') . "\n" . 'Last Name: ' . $request->getParam('landlord_lastname') . "\n" . 'Address: ' . $request->getParam('landlord_address') . "\n" . 'Postcode: ' . $request->getParam('landlord_postcode') . "\n" . 'Telno: ' . $request->getParam('landlord_landlinenumber') . "\n" . 'Mobile: ' . $request->getParam('landlord_mobilenumber') . "\n" . "\nCompany Details: \n" . 'Company Name: ' . $request->getParam('company_name') . "\n" . 'Trading Name: ' . $request->getParam('company_tradingname') . "\n" . 'Registered Number: ' . $request->getParam('company_registration') . "\n" . 'Incorporation Date: ' . $request->getParam('company_incorporation') . "\n" . 'Contact Name: ' . $request->getParam('company_contactname') . "\n" . 'Telno: ' . $request->getParam('company_phone') . "\n" . "\nCompany Registered Address: \n" . 'Address: ' . $request->getParam('registered_address') . "\n" . 'Postcode: ' . $request->getParam('registered_postcode') . "\n" . 'Period at Address: ' . $request->getParam('registered_years') . " years, " . $request->getParam('registered_months') . " months\n" . "\nCompany Trading Address: \n" . 'Address: ' . $request->getParam('trading_address') . "\n" . 'Postcode: ' . $request->getParam('trading_postcode') . "\n" . 'Period at Address: ' . $request->getParam('trading_years') . " years, " . $request->getParam('trading_months') . " months\n" . "\nAdditional Info: \n" . $request->getParam('additional_info') . "\n" . "\nCompany Signature Details: \n" . 'Name: ' . $request->getParam('representive_name') . "\n" . 'Position: ' . $request->getParam('representive_position') . "\n" . 'Date: ' . $request->getParam('application_date') . "\n";
             // Instantiate mailer manager
             $mailManager = new Application_Core_Mail();
             $mailManager->setTo($this->_params->connect->companyapps->emailToAddress, $this->_params->connect->companyapps->emailToName)->setFrom($this->_params->connect->companyapps->emailFromAddress, $this->_params->connect->companyapps->emailFromName)->setSubject($this->_params->connect->companyapps->emailSubject)->setBodyText($message);
             // Check for uploaded file and persist it if so
             list($fileResult, $fileData) = $this->_uploadPersistentCompanyApplicationFile();
             if ($fileResult === true) {
                 $this->view->fileUploaded = $fileData;
                 // If there's a file, attach it
                 if (isset($fileData['pathToFile'])) {
                     $mailManager->addAttachment($fileData['pathToFile'], $fileData['originalName']);
                 }
                 $mailManager->send();
                 // Clean up uploaded file
                 $this->_deleteCompanyApplicationFile();
                 // Show user confirmation that form submission has been successful
                 $this->_helper->viewRenderer('company-confirmation');
             } else {
                 $this->_helper->flashmessages->addMessage('Problem(s) uploading file:');
                 $this->_helper->flashmessages->addMessage($fileData);
             }
         } else {
             // Tell user there are problems
             $this->_helper->flashmessages->addMessage('Problem(s) in form data:');
             $this->_helper->flashmessages->addMessage($pageForm->getMessagesFlattened(true));
             // Check for uploaded file and persist it if so
             list($fileResult, $fileData) = $this->_uploadPersistentCompanyApplicationFile();
             if ($fileResult === true) {
                 $this->view->fileUploaded = $fileData;
             } else {
                 $this->_helper->flashmessages->addMessage('Problem(s) uploading file:');
                 $this->_helper->flashmessages->addMessage($fileData);
             }
         }
     } else {
         // Form first shown, set a couple of default values
         $pageForm->subform_additional->getElement('additional_info')->setValue('Use this space to provide any additional information that may help us when processing your application.');
         $pageForm->subform_declaration->getElement('application_date')->setValue(date('d/m/Y'));
         // Ensure any previously uploaded file is deleted
         $this->_deleteCompanyApplicationFile();
     }
     $this->view->flashMessages = $this->_helper->flashmessages->getCurrentMessages();
     $this->view->form = $pageForm;
 }
 public function sendPdfAction()
 {
     // Check user is logged in to get ASN from
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('hl_connect'));
     if ($auth->hasIdentity()) {
         // Fetch ASN and agent user ID
         $asn = $auth->getStorage()->read()->agentschemeno;
         $userId = $auth->getStorage()->read()->agentid;
         $request = $this->getRequest();
         if (!is_null($request->getParam('filename'))) {
             $filename = $request->getParam('filename');
             // Is this a special agent application form that requires content injection and is sent to a specific agent user?
             if (preg_match('/agent-form\\?form=([\\w\\-]+)$/i', $filename, $matches) > 0) {
                 // Yes, requires agent content injection and sending
                 $formName = $matches[1];
                 $agentFormManager = new Manager_Connect_AgentForm();
                 $agentFormManager->populateAndOuput($formName, $asn, $userId, 'email');
                 echo "{\"successMessage\":\"Email sent\"}\n";
                 exit;
             } else {
                 // Standard PDF, load and send as-is
                 $filters = array('*' => array('StringTrim', 'HtmlEntities', 'StripTags'));
                 // Check e-mail present and valid
                 $formInput['to'] = htmlentities($request->getParam('to'));
                 $formInput['message'] = htmlentities($request->getParam('message'));
                 $formInput['filename'] = htmlentities($request->getParam('filename'));
                 $emailValidator = new Zend_Validate_EmailAddress();
                 $emailValidator->setMessages(array(Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'Domain name invalid in email address', Zend_Validate_EmailAddress::INVALID_FORMAT => 'Invalid email address'));
                 $validators = array('*' => array('allowEmpty' => true), 'email' => $emailValidator);
                 $validate = new Zend_Filter_Input($filters, $validators, $formInput);
                 if ($validate->isValid()) {
                     // Security - ensure PDF can only be requested from public webspace
                     $params = Zend_Registry::get('params');
                     $realpath = realpath($params->connect->basePublicPath . $validate->filename);
                     if (strpos($realpath, $params->connect->safePublicRealPathContains) !== false && strtolower(substr($realpath, -4, 4)) == '.pdf') {
                         // Generate e-mail
                         $mailer = new Application_Core_Mail();
                         $mailer->setTo($validate->to, $validate->to);
                         // TODO: Parameterise:
                         $mailer->setFrom('*****@*****.**', 'HomeLet');
                         $mailer->setSubject("{$validate->filename} sent by HomeLet");
                         $mailer->setBodyText($validate->message);
                         $mailer->addAttachment($realpath, $validate->filename);
                         $mailer->send();
                         echo "{\"successMessage\":\"Email sent\"}\n";
                         exit;
                     }
                 } else {
                     echo "{\"errorMessage\":\"Invalid e-mail address\"}\n";
                     exit;
                 }
             }
         } else {
             echo "{\"errorMessage\":\"No PDF specified\"}\n";
             exit;
         }
     }
     echo "{\"errorMessage\":\"There was an error, please try again later\"}\n";
 }