src/snac/server/mailer/Mailer.php
/**
     * Send Message as Email
     *
     * Sends a message object as an email to its recipient.
     *
     * @param \snac\data\Message $message The message to send via email
     */
Send Message as Email
Sends a message object as an email to its recipient.

@param \snac\data\Message $message The message to send via email
Send Message as Email Sends a message object as an email to its recipient . @param \ snac \ data \ Message $message The message to send via email
public function sendUserMessage(&$message) {
        $this->logger->addDebug('Trying to send message', $message->toArray());
        $this->mailer->setFrom($this->fromEmail, $this->fromName);
        $toEmail = $message->getToUser()->getEmail();
        if ($message->getToUser()->getWorkEmail() !== null)
            $toEmail = $message->getToUser()->getWorkEmail();
        $this->mailer->addAddress($toEmail, $message->getToUser()->getFullName()); 
        $this->mailer->isHTML(true);                                            
        $this->mailer->Subject = "SNAC Mail: " . $message->getSubject();
        $this->logger->addDebug('Building template message');
        $loader = new \Twig_Loader_Filesystem(\snac\Config::$EMAIL_TEMPLATE_DIR);
        $twig = new \Twig_Environment($loader, array());
        $this->logger->addDebug('Building HTML template message');
        $htmlBody = $twig->render("default.html", $message->toArray());
        $this->mailer->Body    = $htmlBody;
        $this->logger->addDebug('Building TXT template message');
        $textMessage = $message->toArray();
        $textMessage["body"] = \Html2Text\Html2Text::convert($message->getBody());
        $textBody = $twig->render("default.txt", $textMessage);
        $this->mailer->AltBody    = $textBody;
        $this->logger->addDebug('Sending message');
        if(!$this->mailer->send()) {
            $this->logger->addDebug('Message could not be sent: ' . $this->mailer->ErrorInfo);
        }
        $this->resetMailer();
    }
public function sendUserMessage ( & $ message ) { $ this -> logger -> addDebug ( 'Trying to send message' , $ message -> toArray ( ) ) ; $ this -> mailer -> setFrom ( $ this -> fromEmail , $ this -> fromName ) ; $ toEmail = $ message -> getToUser ( ) -> getEmail ( ) ; if ( $ message -> getToUser ( ) -> getWorkEmail ( ) !== null ) $ toEmail = $ message -> getToUser ( ) -> getWorkEmail ( ) ; $ this -> mailer -> addAddress ( $ toEmail , $ message -> getToUser ( ) -> getFullName ( ) ) ; $ this -> mailer -> isHTML ( true ) ; $ this -> mailer -> Subject = " SNAC Mail:  " . $ message -> getSubject ( ) ; $ this -> logger -> addDebug ( 'Building template message' ) ; $ loader = new \ Twig_Loader_Filesystem ( \ snac \ Config :: $ EMAIL_TEMPLATE_DIR ) ; $ twig = new \ Twig_Environment ( $ loader , array ( ) ) ; $ this -> logger -> addDebug ( 'Building HTML template message' ) ; $ htmlBody = $ twig -> render ( " default.html " , $ message -> toArray ( ) ) ; $ this -> mailer -> Body = $ htmlBody ; $ this -> logger -> addDebug ( 'Building TXT template message' ) ; $ textMessage = $ message -> toArray ( ) ; $ textMessage [ " body " ] = \ Html2Text \ Html2Text :: convert ( $ message -> getBody ( ) ) ; $ textBody = $ twig -> render ( " default.txt " , $ textMessage ) ; $ this -> mailer -> AltBody = $ textBody ; $ this -> logger -> addDebug ( 'Sending message' ) ; if ( ! $ this -> mailer -> send ( ) ) { $ this -> logger -> addDebug ( 'Message could not be sent: ' . $ this -> mailer -> ErrorInfo ) ; } $ this -> resetMailer ( ) ; }
Send Message as Email
 Sends a message object as an email to its recipient.
Send Message as Email Sends a message object as an email to its recipient .
// Add a recipient // Set email format to HTML // Use Twig to style the message body using the snac style