示例#1
0
 /**
  * PPI Mail Sending Functioin
  * @param array $p_aOptions The options for sending to the mail library
  * @uses $p_aOptions[subject, body, toaddr] are all mandatory.
  * @uses Options available are toname
  * @return boolean The result of the mail sending process
  */
 static function sendMail(array $p_aOptions)
 {
     $oConfig = PPI_Helper::getConfig();
     $oEmail = new PPI_Model_Email_Advanced();
     if (!isset($p_aOptions['subject'], $p_aOptions['body'], $p_aOptions['toaddr'])) {
         throw new PPI_Exception('Invalid parameters to sendMail');
     }
     $oEmail->Subject = $p_sSubject;
     if (isset($p_aOptions['fromaddr'], $p_aOptions['fromname'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr'], $p_aOptions['fromname']);
     } elseif (isset($p_aOptions['fromaddr'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr']);
     } else {
         $oEmail->SetFrom($oConfig->system->adminEmail, $oConfig->system->adminName);
     }
     if (isset($p_aOptions['toaddr'], $p_aOptions['toname'])) {
         $oEmail->AddAddress($p_aOptions['toaddr'], $p_aOptions['toname']);
     } elseif (isset($p_aOptions['toaddr'])) {
         $oEmail->AddAddress($p_aOptions['toaddr']);
     }
     if (isset($p_aOptions['altbody'])) {
         $oEmail->AltBody = $p_sMessage;
     }
     $oEmail->MsgHTML($p_aOptions['body']);
     // If the email sent successfully,
     return $oEmail->Send();
     // @todo - Log the email sending process.
 }
示例#2
0
 /**
  * Send the password recovery email to the user.
  * @param string $p_sEmail The Email Address
  * @param string $p_sSubject The Subject
  * @param string $p_sMessage The Message
  * @return boolean
  */
 function sendRecoverEmail($p_aUser, $p_sSubject = '', $p_sMessage = '')
 {
     $oConfig = $this->getConfig();
     if ($p_sSubject === '') {
         $p_sSubject = 'Password recovery';
     }
     $sRecoveryCode = base64_encode(time());
     if ($p_sMessage === '') {
         $p_sMessage = "Hi, {$p_aUser['first_name']}\n\nYou have requested a password recovery and your password has now been reset.\nPlease click the following verification link to reset your password.\n";
         $p_sMessage .= $oConfig->system->base_url . 'user/recover/' . urlencode($sRecoveryCode);
     }
     $oEmail = new PPI_Model_Email_Advanced();
     $oEmail->Subject = $p_sSubject;
     $oEmail->SetFrom($oConfig->system->adminEmail, $oConfig->system->adminName);
     $oEmail->AddAddress($p_aUser['email']);
     $oEmail->AltBody = $p_sMessage;
     $oEmail->MsgHTML($p_sMessage);
     // If the email sent successfully,
     if ($oEmail->Send()) {
         $oUser = new APP_Model_User();
         $sPrimaryKey = $oUser->getPrimaryKey();
         // Lets update the users record with their recovery_code
         $oUser->putRecord(array('recovery_code' => $sRecoveryCode, $sPrimaryKey => $p_aUser[$sPrimaryKey]));
         return true;
     }
     return false;
 }