public static function notifyUser($user, $password) { PHPWS_Core::initCoreClass('Mail.php'); $page_title = Layout::getPageTitle(true); $body[] = sprintf(dgettext('users', '%s created an user account for you.'), $page_title); $body[] = dgettext('users', 'You may log-in using the following information:'); $body[] = sprintf(dgettext('users', 'Site address: %s'), PHPWS_Core::getHomeHttp()); $body[] = sprintf(dgettext('users', 'Username: %s'), $user->username); $body[] = sprintf(dgettext('users', 'Password: %s'), $password); $body[] = dgettext('users', 'Please change your password immediately after logging in.'); $mail = new PHPWS_Mail(); $mail->addSendTo($user->email); $mail->setSubject(sprintf(dgettext('users', '%s account created'), $page_title)); $mail->setFrom(PHPWS_User::getUserSetting('site_contact')); $mail->setReplyTo(PHPWS_User::getUserSetting('site_contact')); $mail->setMessageBody(implode("\n\n", $body)); $result = $mail->send(); return $result; }
/** * Sends everyone (limited by search) in a specific sheet an email */ public function sendEmail() { PHPWS_Core::initCoreClass('Mail.php'); if (!isset($_SESSION['Email_Applicants'])) { $_SESSION['Email_Applicants']['email'] =& $this->email; $_SESSION['Email_Applicants']['sheet_id'] = $this->sheet->id; $_SESSION['Email_Applicants']['search'] = @$_REQUEST['search']; $vars['aop'] = 'send_email'; Layout::metaRoute(PHPWS_Text::linkAddress('signup', $vars, true), 1); $this->title = dgettext('signup', 'Sending emails'); $this->content = dgettext('signup', 'Please wait'); return; } $email_session =& $_SESSION['Email_Applicants']; $mail = new PHPWS_Mail(); $mail->setSubject($email_session['email']['subject']); $mail->setFrom($email_session['email']['from']); $mail->setReplyTo($email_session['email']['from']); $mail->setMessageBody($email_session['email']['message']); $mail->sendIndividually(true); $this->loadSheet($email_session['sheet_id']); if (!$this->sheet->id) { $this->title = dgettext('signup', 'Sorry'); $this->content = dgettext('signup', 'Unable to send emails. Signup sheet does not exist.'); PHPWS_Core::killSession('Email_Applicants'); return; } $db = new PHPWS_DB('signup_peeps'); $db->addColumn('email'); $db->addWhere('sheet_id', $this->sheet->id); if (isset($email_session['search'])) { $search = explode('+', $email_session['search']); foreach ($search as $s) { $db->addWhere('first_name', "%{$s}%", 'like', 'or', 1); $db->addWhere('last_name', "%{$s}%", 'like', 'or', 1); } } $result = $db->select('col'); if (empty($result)) { $this->title = dgettext('signup', 'Emails not sent'); $this->content = dgettext('signup', 'Signup sheet did not contain any applicants.'); return; } elseif (PHPWS_Error::logIfError($result)) { $this->title = dgettext('signup', 'Emails not sent'); $this->content = dgettext('signup', 'An error occurred when pulling applicants.'); return; } foreach ($result as $address) { $mail->addSendTo($address); } $mail->send(); $vars['aop'] = 'report'; $vars['sheet_id'] = $this->sheet->id; $link = PHPWS_Text::linkAddress('signup', $vars, true); $this->title = dgettext('signup', 'Emails sent'); $this->content = dgettext('signup', 'Returning to applicant listing.'); Layout::metaRoute($link, 5); PHPWS_Core::killSession('Email_Applicants'); }