Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsendmailtransport.php
Go to the documentation of this file.
1 <?php
19 class eZSendmailTransport extends eZMailTransport
20 {
21 function sendMail( eZMail $mail )
22 {
23 $ini = eZINI::instance();
24 $sendmailOptions = '';
25 $emailFrom = $mail->sender();
26 $emailSender = isset( $emailFrom['email'] ) ? $emailFrom['email'] : false;
27 if ( !$emailSender || ( is_countable( $emailSender ) && count( $emailSender) <= 0 ) )
28 $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
29 if ( !$emailSender )
30 $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );
31 if ( !eZMail::validate( $emailSender ) )
32 $emailSender = false;
33
34 $sendmailOptionsArray = $ini->variable( 'MailSettings', 'SendmailOptions' );
35 if( is_array($sendmailOptionsArray) )
36 $sendmailOptions = implode( ' ', $sendmailOptionsArray );
37 elseif( !is_string($sendmailOptionsArray) )
38 $sendmailOptions = $sendmailOptionsArray;
39 if ( $emailSender )
40 $sendmailOptions .= ' -f' . escapeshellarg( $emailSender );
41
42 if( function_exists( 'mail' ) )
43 {
44 $message = $mail->body();
45 $sys = eZSys::instance();
46 $excludeHeaders = array( 'Subject' );
47 // If not Windows PHP mail() implementation, we can not specify a To: header in the $additional_headers parameter,
48 // because then there will be 2 To: headers in the resulting e-mail.
49 // However, we can use "undisclosed-recipients:;" in $to.
50 if ( $sys->osType() != 'win32' )
51 {
52 $excludeHeaders[] = 'To';
53 $insertUndisclosedRecipient = $ini->variable( 'MailSettings', 'SendmailInsertUndisclosedRecipient' );
54 $recipientText = $insertUndisclosedRecipient == 'disabled' ? '' : 'undisclosed-recipients:;';
55 $receiverEmailText = count( $mail->ReceiverElements ) > 0 ? $mail->receiverEmailText() : $recipientText;
56 }
57 // If Windows PHP mail() implementation, we can specify a To: header in the $additional_headers parameter,
58 // it will be used as the only To: header.
59 // We can not use "undisclosed-recipients:;" in $to, it will result in a SMTP server response: 501 5.1.3 Bad recipient address syntax
60 else
61 {
62 $receiverEmailText = $mail->receiverEmailText();
63 }
64
65 // If in debug mode, send to debug email address and nothing else
66 if ( $ini->variable( 'MailSettings', 'DebugSending' ) == 'enabled' )
67 {
68 $receiverEmailText = $ini->variable( 'MailSettings', 'DebugReceiverEmail' );
69 $excludeHeaders[] = 'To';
70 $excludeHeaders[] = 'Cc';
71 $excludeHeaders[] = 'Bcc';
72 }
73
74 $extraHeaders = $mail->headerText( array( 'exclude-headers' => $excludeHeaders ) );
75
76 $returnedValue = mail( $receiverEmailText, $mail->subject(), $message, $extraHeaders, $sendmailOptions );
77 if ( $returnedValue === false )
78 {
79 eZDebug::writeError( 'An error occurred while sending e-mail. Check the Sendmail error message for further information (usually in /var/log/messages)',
80 __METHOD__ );
81 }
82
83 return $returnedValue;
84 }
85 else
86 {
87 eZDebug::writeWarning( "Unable to send mail: 'mail' function is not compiled into PHP.", __METHOD__ );
88 }
89
90 return false;
91 }
92 }
93
94 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZMailTransport
Interface for mail transport handling.
Definition: ezmailtransport.php:18
eZMail
Mail handler.
Definition: ezmail.php:60
eZMail\subject
subject( $convert=true)
Definition: ezmail.php:666
eZMail\headerText
headerText( $parameters=array())
Definition: ezmail.php:1020
eZMail\receiverEmailText
receiverEmailText( $convert=true)
Definition: ezmail.php:101
eZMail\sender
sender( $convert=true)
Definition: ezmail.php:250
eZMail\body
body( $convert=true)
Definition: ezmail.php:691
eZMail\validate
static validate( $address)
Definition: ezmail.php:747
eZSendmailTransport
Sends the email message to sendmail which takes care of sending the actual message.
Definition: ezsendmailtransport.php:20
eZSendmailTransport\sendMail
sendMail(eZMail $mail)
Definition: ezsendmailtransport.php:21
eZSys\instance
static instance()
Definition: ezsys.php:1272
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.