eZ Publish  [trunk]
ezsmtptransport.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZSMTPTransport class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package lib
00009  */
00010 
00011 /*!
00012   \class eZSMTPTransport ezsmtptransport.php
00013   \brief The class eZSMTPTransport does
00014 
00015 */
00016 
00017 class eZSMTPTransport extends eZMailTransport
00018 {
00019     /*!
00020      Constructor
00021     */
00022     function eZSMTPTransport()
00023     {
00024     }
00025 
00026     function sendMail( eZMail $mail )
00027     {
00028         $ini = eZINI::instance();
00029         $parameters = array();
00030         $parameters['host'] = $ini->variable( 'MailSettings', 'TransportServer' );
00031         $parameters['helo'] = $ini->variable( 'MailSettings', 'SenderHost' );
00032         $parameters['port'] = $ini->variable( 'MailSettings', 'TransportPort' );
00033         $parameters['connectionType'] = $ini->variable( 'MailSettings', 'TransportConnectionType' );
00034         $user = $ini->variable( 'MailSettings', 'TransportUser' );
00035         $password = $ini->variable( 'MailSettings', 'TransportPassword' );
00036         if ( $user and
00037              $password )
00038         {
00039             $parameters['auth'] = true;
00040             $parameters['user'] = $user;
00041             $parameters['pass'] = $password;
00042         }
00043 
00044         /* If email sender hasn't been specified or is empty
00045          * we substitute it with either MailSettings.EmailSender or AdminEmail.
00046          */
00047         if ( !$mail->senderText() )
00048         {
00049             $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
00050             if ( !$emailSender )
00051                 $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );
00052 
00053             eZMail::extractEmail( $emailSender, $emailSenderAddress, $emailSenderName );
00054 
00055             if ( !eZMail::validate( $emailSenderAddress ) )
00056                 $emailSender = false;
00057 
00058             if ( $emailSender )
00059                 $mail->setSenderText( $emailSender );
00060         }
00061 
00062         $excludeHeaders = $ini->variable( 'MailSettings', 'ExcludeHeaders' );
00063         if ( count( $excludeHeaders ) > 0 )
00064             $mail->Mail->appendExcludeHeaders( $excludeHeaders );
00065 
00066         $options = new ezcMailSmtpTransportOptions();
00067         if( $parameters['connectionType'] )
00068         {
00069             $options->connectionType = $parameters['connectionType'];
00070         }
00071         $smtp = new ezcMailSmtpTransport( $parameters['host'], $user, $password,
00072         $parameters['port'], $options );
00073 
00074         // If in debug mode, send to debug email address and nothing else
00075         if ( $ini->variable( 'MailSettings', 'DebugSending' ) == 'enabled' )
00076         {
00077             $mail->Mail->to = array( new ezcMailAddress( $ini->variable( 'MailSettings', 'DebugReceiverEmail' ) ) );
00078             $mail->Mail->cc = array();
00079             $mail->Mail->bcc = array();
00080         }
00081 
00082         // send() from ezcMailSmtpTransport doesn't return anything (it uses exceptions in case
00083         // something goes bad)
00084         try
00085         {
00086             $smtp->send( $mail->Mail );
00087         }
00088         catch ( ezcMailException $e )
00089         {
00090             eZDebug::writeError( $e->getMessage(), __METHOD__ );
00091             return false;
00092         }
00093 
00094         // return true in case of no exceptions
00095         return true;
00096     }
00097 }
00098 
00099 ?>