File modules/cms/action/profile/ProfileMailAction.class.php

Last commit: Wed Oct 27 02:27:59 2021 +0200	Jan Dankert	Refactoring: Splitted the mail client into a.) sendmail and b.) smtp.
1 <?php 2 namespace cms\action\profile; 3 use cms\action\Method; 4 use cms\action\ProfileAction; 5 use language\Messages; 6 use logger\Logger; 7 use util\exception\ValidationException; 8 use util\mail\Mail; 9 use util\Session; 10 use util\text\TextMessage; 11 12 class ProfileMailAction extends ProfileAction implements Method { 13 14 public function view() { 15 } 16 17 public function post() { 18 srand ((double)microtime()*1000003); 19 $code = rand(); // Zufalls-Freischaltcode erzeugen 20 $newMail = $this->request->getText('mail'); 21 22 if ( !$newMail ) 23 { 24 // Keine E-Mail-Adresse eingegeben. 25 throw new ValidationException('mail'); 26 } 27 else 28 { 29 // Der Freischaltcode wird in der Sitzung gespeichert. 30 Session::set( Session::KEY_MAIL_CHANGE_CODE,$code ); 31 Session::set( Session::KEY_MAIL_CHANGE_MAIL,$newMail); 32 33 // E-Mail an die neue Adresse senden. 34 $mail = new Mail($newMail, Messages::MAIL_SUBJECT_MAIL_CHANGE_CODE,Messages::MAIL_TEXT_MAIL_CHANGE_CODE); 35 $mail->setVar('code',$code ); 36 $mail->setVar('name',$this->user->getName()); 37 38 try { 39 $mail->send(); 40 $this->addNoticeFor( $this->user, Messages::MAIL_SENT); 41 } catch( \Exception $e ) { 42 Logger::warn( new \Exception( TextMessage::create('Mail could not be sent for user ${name} with the new email adress ${mail} ',['name'=>$this->user->name,'mail'=>$newMail]),0,$e) ); 43 $this->addErrorFor($this->user, Messages::MAIL_NOT_SENT ); 44 } 45 } 46 } 47 }
Download modules/cms/action/profile/ProfileMailAction.class.php
History Wed, 27 Oct 2021 02:27:59 +0200 Jan Dankert Refactoring: Splitted the mail client into a.) sendmail and b.) smtp. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Thu, 19 Nov 2020 16:05:15 +0100 Jan Dankert Refactoring: Better exception handling in class Mail; multiple CC and BCC receivers. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.