eZ Publish  [4.0]
ezsmtptransport.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZSMTPTransport class
00004 //
00005 // Created on: <10-Dec-2002 15:20:20 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezsmtptransport.php
00032 */
00033 
00034 /*!
00035   \class eZSMTPTransport ezsmtptransport.php
00036   \brief The class eZSMTPTransport does
00037 
00038 */
00039 
00040 //include_once( 'lib/ezutils/classes/ezmailtransport.php' );
00041 
00042 class eZSMTPTransport extends eZMailTransport
00043 {
00044     /*!
00045      Constructor
00046     */
00047     function eZSMTPTransport()
00048     {
00049     }
00050 
00051     /*!
00052      \reimp
00053     */
00054     function sendMail( eZMail $mail )
00055     {
00056         $ini = eZINI::instance();
00057         $parameters = array();
00058         $parameters['host'] = $ini->variable( 'MailSettings', 'TransportServer' );
00059         $parameters['helo'] = $ini->variable( 'MailSettings', 'SenderHost' );
00060         $parameters['port'] = $ini->variable( 'MailSettings', 'TransportPort' );
00061         $user = $ini->variable( 'MailSettings', 'TransportUser' );
00062         $password = $ini->variable( 'MailSettings', 'TransportPassword' );
00063         if ( $user and
00064              $password )
00065         {
00066             $parameters['auth'] = true;
00067             $parameters['user'] = $user;
00068             $parameters['pass'] = $password;
00069         }
00070 
00071         /* If email sender hasn't been specified or is empty
00072          * we substitute it with either MailSettings.EmailSender or AdminEmail.
00073          */
00074         if ( !$mail->senderText() )
00075         {
00076             $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
00077             if ( !$emailSender )
00078                 $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );
00079 
00080             eZMail::extractEmail( $emailSender, $emailSenderAddress, $emailSenderName );
00081 
00082             if ( !eZMail::validate( $emailSenderAddress ) )
00083                 $emailSender = false;
00084 
00085             if ( $emailSender )
00086                 $mail->setSenderText( $emailSender );
00087         }
00088 
00089         $sendData = array();
00090 //        $sendData['from'] = $mail->senderText();
00091         $from = $mail->sender();
00092         $sendData['from'] = isset( $from['email'] ) ? $from['email'] : '';
00093         $sendData["recipients"] = $mail->receiverTextList();
00094         $sendData['CcRecipients'] = $mail->ccReceiverTextList();
00095         $sendData['BccRecipients'] = $mail->bccReceiverTextList();
00096         $sendData['headers'] = $mail->headerTextList();
00097         $sendData['body'] = $mail->body();
00098 
00099         //include_once( "lib/ezutils/classes/ezsmtp.php" );
00100 
00101         $smtp = new smtp( $parameters );
00102         $smtpConnected = $smtp->connect();
00103         if ( $smtpConnected )
00104         {
00105             $result = $smtp->send( $sendData );
00106             $mailSent = true;
00107             if ( isset( $smtp->errors ) and is_array( $smtp->errors ) and count( $smtp->errors ) > 0 )
00108             {
00109                 $mailSent = false;
00110                 foreach ( $smtp->errors as $error )
00111                 {
00112                     eZDebug::writeError( "Error sending SMTP mail: " . $error, "eZSMTPTransport::sendMail()" );
00113                 }
00114             }
00115             $smtp->quit();
00116         }
00117         else
00118             $mailSent = false;
00119         return $mailSent;
00120     }
00121 }
00122 
00123 ?>