示例#1
0
 public function executeSendmail()
 {
     $subject = $this->getRequestParameter('subject');
     $body = $this->getRequestParameter('mailbody');
     $loggeduser = UserPeer::retrieveByPK($this->getUser()->getAttribute('userid'));
     $sendermail = $loggeduser->getEmail();
     $sendername = $loggeduser->getFullname();
     $counts = 0;
     $countf = 0;
     if ($this->getRequestParameter('type') == 'one') {
         $user = UserPeer::retrieveByPK($this->getRequestParameter('toid'));
         $tomail = $user->getEmail();
         $toname = $user->getFullname();
         //$mail = myUtility::sendmail($sendermail, $sendername, $sendermail, $sendername, $sendermail, $tomail, $subject, $body);
         $mail = new Mails();
         $mail->setApproved(0);
         $mail->setSubject($subject);
         $mail->setMessage($body);
         $mail->setSendername($sendername);
         $mail->setSendermail($sendermail);
         $mail->setRecipientmail($tomail);
         $mail->setRecipientname($toname);
         $mail->save();
         $this->setFlash('notice', 'Mail to <b>' . $user->getFullname() . '</b> has been saved successfully. Will be sent after approval');
     } elseif ($this->getRequestParameter('type') == 'bulk') {
         $userids = $this->getUser()->getAttribute('bulkmailids');
         $this->getUser()->getAttributeHolder()->remove('bulkmailids');
         foreach ($userids as $uid) {
             $user = UserPeer::retrieveByPK($uid);
             $tomail = $user->getEmail();
             $toname = $user->getFullname();
             if ($tomail) {
                 //$mail = myUtility::sendmail($sendermail, $sendername, $sendermail, $sendername, $sendermail, $to, $subject, $body);
                 $mail = new Mails();
                 $mail->setApproved(0);
                 $mail->setSubject($subject);
                 $mail->setMessage($body);
                 $mail->setSendername($sendername);
                 $mail->setSendermail($sendermail);
                 $mail->setRecipientmail($tomail);
                 $mail->setRecipientname($toname);
                 $mail->save();
                 $counts++;
             } else {
                 $countf++;
             }
         }
         $this->setFlash('notice', '<b>' . $counts . '</b> mails saved succesfully for approval users successfully. While <b>' . $countf . '</b> users dont have an email.');
     }
     $this->redirect('search/result?page=' . $this->getUser()->getAttribute('srpage'));
     /*$sendermail = sfConfig::get('app_from_mail');
     		$sendername = sfConfig::get('app_from_name');*/
     /*$userids = $this->getUser()->getAttribute('uu');
     		$this->getUser()->getAttributeHolder()->remove('uu');*/
     /*		if($option == 'm'){
     			echo count($userids);
     			foreach ($userids as $uid){
     				echo "hello";
     				$ab = $uid;
     				$user = UserPeer::retrieveByPK($uid);
     				$to = $user->getEmail();
     				$mail = myUtility::sendmail($sendermail, $sendername, $sendermail, $sendername, $sendermail, $to, $subject, $body);
     			}
     		}
     		else {
     		echo count($userids);
     			foreach ($userids as $uid){
     				echo "hello";
     				$ab = $uid;
     				$user = UserPeer::retrieveByPK($uid);
     				$to = $user->getEmail();
     				$mail = myUtility::sendmail($sendermail, $sendername, $sendermail, $sendername, $sendermail, $to, $subject, $body);
     			}
     		}*/
 }