The implementation supports most of the commands specified in: - {@link http://www.faqs.org/rfcs/rfc821.html RFC821 - SMTP} - {@link http://www.faqs.org/rfcs/rfc2554.html RFC2554 - SMTP Authentication} - {@link http://www.faqs.org/rfcs/rfc2831.html RFC2831 - DIGEST-MD5 Authentication} - {@link http://www.faqs.org/rfcs/rfc2195.html RFC2195 - CRAM-MD5 Authentication} - {@link http://davenport.sourceforge.net/ntlm.html NTLM Authentication} By default, the SMTP transport tries to login anonymously to the SMTP server (if an empty username and password have been provided), or to authenticate with the strongest method supported by the server (if username and password have been provided). The default behaviour can be changed with the option preferredAuthMethod (see {@link ezcMailSmtpTransportOptions}). If the preferred method is specified via options, only that authentication method will be attempted on the SMTP server. If it fails, an exception will be thrown. Supported authentication methods (from strongest to weakest): - DIGEST-MD5 - CRAM-MD5 - NTLM (requires the PHP mcrypt extension) - XOAUTH2 - LOGIN - PLAIN Not all SMTP servers support these methods, and some SMTP servers don't support authentication at all. Example send mail: $mail = new ezcMailComposer(); $mail->from = new ezcMailAddress( 'sender@example.com', 'Adrian Ripburger' ); $mail->addTo( new ezcMailAddress( 'receiver@example.com', 'Maureen Corley' ) ); $mail->subject = "This is the subject of the example mail"; $mail->plainText = "This is the body of the example mail."; $mail->build(); Create a new SMTP transport object with an SSLv3 connection. The port will be 465 by default, use the 4th argument to change it. Username and password (2nd and 3rd arguments) are left blank, which means the mail host does not need authentication. The 5th parameter is the optional $options object. $options = new ezcMailSmtpTransportOptions(); $options->connectionType = ezcMailSmtpTransport::CONNECTION_SSLV3; $transport = new ezcMailSmtpTransport( 'mailhost.example.com', '', '', null, $options ); Use the SMTP transport to send the created mail object $transport->send( $mail ); Example require NTLM authentication: Create an SMTP transport and demand NTLM authentication. Username and password must be specified, otherwise no authentication will be attempted. If NTLM authentication fails, an exception will be thrown. $options = new ezcMailSmtpTransportOptions(); $options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; $transport = new ezcMailSmtpTransport( 'mailhost.example.com', 'username', 'password', null, $options ); The option can also be specified via the option property: $transport->options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM; See {@link ezcMailSmtpTransportOptions} for options you can specify for SMTP.
Inheritance: implements ezcMailTransport
 function sendMail(eZMail $mail)
 {
     $ini = eZINI::instance();
     $parameters = array();
     $parameters['host'] = $ini->variable('MailSettings', 'TransportServer');
     $parameters['helo'] = $ini->variable('MailSettings', 'SenderHost');
     $parameters['port'] = $ini->variable('MailSettings', 'TransportPort');
     $parameters['connectionType'] = $ini->variable('MailSettings', 'TransportConnectionType');
     $user = $ini->variable('MailSettings', 'TransportUser');
     $password = $ini->variable('MailSettings', 'TransportPassword');
     if ($user and $password) {
         $parameters['auth'] = true;
         $parameters['user'] = $user;
         $parameters['pass'] = $password;
     }
     /* If email sender hasn't been specified or is empty
      * we substitute it with either MailSettings.EmailSender or AdminEmail.
      */
     if (!$mail->senderText()) {
         $emailSender = $ini->variable('MailSettings', 'EmailSender');
         if (!$emailSender) {
             $emailSender = $ini->variable('MailSettings', 'AdminEmail');
         }
         eZMail::extractEmail($emailSender, $emailSenderAddress, $emailSenderName);
         if (!eZMail::validate($emailSenderAddress)) {
             $emailSender = false;
         }
         if ($emailSender) {
             $mail->setSenderText($emailSender);
         }
     }
     $excludeHeaders = $ini->variable('MailSettings', 'ExcludeHeaders');
     if (count($excludeHeaders) > 0) {
         $mail->Mail->appendExcludeHeaders($excludeHeaders);
     }
     $options = new ezcMailSmtpTransportOptions();
     if ($parameters['connectionType']) {
         $options->connectionType = $parameters['connectionType'];
     }
     $smtp = new ezcMailSmtpTransport($parameters['host'], $user, $password, $parameters['port'], $options);
     // If in debug mode, send to debug email address and nothing else
     if ($ini->variable('MailSettings', 'DebugSending') == 'enabled') {
         $mail->Mail->to = array(new ezcMailAddress($ini->variable('MailSettings', 'DebugReceiverEmail')));
         $mail->Mail->cc = array();
         $mail->Mail->bcc = array();
     }
     // send() from ezcMailSmtpTransport doesn't return anything (it uses exceptions in case
     // something goes bad)
     try {
         eZPerfLogger::accumulatorStart('mail_sent');
         $smtp->send($mail->Mail);
         eZPerfLogger::accumulatorStop('mail_sent');
     } catch (ezcMailException $e) {
         eZPerfLogger::accumulatorStop('mail_send');
         eZDebug::writeError($e->getMessage(), __METHOD__);
         return false;
     }
     // return true in case of no exceptions
     return true;
 }
Ejemplo n.º 2
0
 public static function send($to, $subject, $body, $options = array())
 {
     $siteINI = eZINI::instance('site.ini');
     $i18nINI = eZINI::instance('i18n.ini');
     $transport = $siteINI->variable('MailSettings', 'Transport');
     $charset = $i18nINI->variable('CharacterSettings', 'Charset');
     $emailSender = $siteINI->variable('MailSettings', 'EmailSender');
     if (!$emailSender) {
         $emailSender = $siteINI->variable('MailSettings', 'AdminEmail');
     }
     if ($transport == 'SMTP') {
         $mailTransport = new ezcMailSmtpTransport($siteINI->variable('MailSettings', 'TransportServer'), $siteINI->variable('MailSettings', 'TransportUser'), $siteINI->variable('MailSettings', 'TransportPassword'), $siteINI->variable('MailSettings', 'TransportPort'));
     } else {
         eZDebug::writeError('Only SMTP Transport supported', 'jajNewsletterSubscription::sendConfirmationMail');
         throw new Exception('Only SMTP Transport supported');
     }
     $mail = new ezcMailComposer();
     $mail->charset = $charset;
     $mail->subjectCharset = $charset;
     $mail->subject = $subject;
     $mail->htmlText = $body;
     $mail->from = ezcMailTools::parseEmailAddress($emailSender, $charset);
     $mail->addTo(new ezcMailAddress($to, '', $charset));
     $mail->build();
     $mailTransport->send($mail);
 }
 function sendMail(ezcMail $mail)
 {
     $ini = eZINI::instance();
     $parameters = array();
     $parameters['host'] = $ini->variable('MailSettings', 'TransportServer');
     $parameters['helo'] = $ini->variable('MailSettings', 'TransportServer');
     $parameters['port'] = $ini->variable('MailSettings', 'TransportPort');
     $parameters['connectionType'] = $ini->variable('MailSettings', 'TransportConnectionType');
     $user = $ini->variable('MailSettings', 'TransportUser');
     $password = $ini->variable('MailSettings', 'TransportPassword');
     if ($user and $password) {
         $parameters['auth'] = true;
         $parameters['user'] = $user;
         $parameters['pass'] = $password;
     }
     $options = new ezcMailSmtpTransportOptions();
     if ($parameters['connectionType']) {
         $options->connectionType = $parameters['connectionType'];
     }
     $smtp = new ezcMailSmtpTransport($parameters['host'], $user, $password, $parameters['port'], $options);
     try {
         $smtp->send($mail);
         return true;
     } catch (ezcMailException $e) {
         eZDebug::writeError("Error sending SMTP mail: " . $e->getMessage(), 'eZSMTPTransport::sendMail');
         echo "SMTP ERROR: " . $e->getMessage();
         return false;
     }
     return false;
 }
<?php

$message = new ezcMailComposer();
$message->from = new ezcMailAddress('*****@*****.**');
$message->addTo(new ezcMailAddress('*****@*****.**', 'Adam'));
$message->subject = 'New Version of PHP Released!';
$body = 'Go to http://www.php.net and download it today!';
$message->plainText = $body;
$message->build();
$host = 'smtpauth.example.com';
$username = '******';
$password = '******';
$port = 587;
$smtpOptions = new ezcMailSmtpTransportOptions();
$smtpOptions->preferredAuthMethod = ezcMailSmtpTransport::AUTH_LOGIN;
$sender = new ezcMailSmtpTransport($host, $username, $password, $port, $smtpOptions);
$sender->send($message);
Ejemplo n.º 5
0
 public function testConnectionPlain()
 {
     $this->skipIfNotInNetwork(self::HOST_SSL, self::PORT_SSL);
     try {
         $smtp = new ezcMailSmtpTransport(self::HOST_SSL, self::USER_SSL, self::PASS_SSL, null, array('connectionType' => ezcMailSmtpTransport::CONNECTION_PLAIN));
         $this->mail->subject = __CLASS__ . ':' . __FUNCTION__;
         $smtp->send($this->mail);
     } catch (ezcMailTransportException $e) {
         $this->fail($e->getMessage());
     }
 }
Ejemplo n.º 6
0
 /**
  * Sends the DATA command to the SMTP server.
  *
  * @throws ezcMailTransportSmtpException
  *         if there is no valid connection
  *         or if the DATA command failed
  */
 public function cmdData()
 {
     parent::cmdData();
 }
Ejemplo n.º 7
0
 /**
  * Sets the option $name to $value.
  *
  * @throws ezcBasePropertyNotFoundException
  *         if the property $name is not defined
  * @throws ezcBaseValueException
  *         if $value is not correct for the property $name
  * @param string $name
  * @param mixed $value
  * @ignore
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'connectionType':
             $this->properties[$name] = $value;
             break;
         case 'connectionOptions':
             if (!is_array($value)) {
                 throw new ezcBaseValueException($name, $value, 'array');
             }
             $this->properties[$name] = $value;
             break;
         case 'ssl':
             if (!is_bool($value)) {
                 throw new ezcBaseValueException($name, $value, 'bool');
             }
             $this->properties['connectionType'] = $value === true ? ezcMailSmtpTransport::CONNECTION_SSL : ezcMailSmtpTransport::CONNECTION_PLAIN;
             break;
         case 'preferredAuthMethod':
             $supportedAuthMethods = ezcMailSmtpTransport::getSupportedAuthMethods();
             $supportedAuthMethods[] = ezcMailSmtpTransport::AUTH_AUTO;
             if (!in_array($value, $supportedAuthMethods)) {
                 throw new ezcBaseValueException($name, $value, implode(' | ', $supportedAuthMethods));
             }
             $this->properties[$name] = $value;
             break;
         default:
             parent::__set($name, $value);
     }
 }
Ejemplo n.º 8
0
 public function testAuthPlainWrongPassword()
 {
     try {
         $smtp = new ezcMailSmtpTransport(self::HOST_PLAIN, self::USER_PLAIN, 'wrong password', self::PORT_PLAIN, array('preferredAuthMethod' => ezcMailSmtpTransport::AUTH_PLAIN));
         $this->mail->subject = __CLASS__ . ' - ' . __FUNCTION__;
         $smtp->send($this->mail);
         $this->fail('Expected message was not thrown.');
     } catch (ezcMailTransportException $e) {
     }
 }
Ejemplo n.º 9
0
<?php

require_once 'tutorial_autoload.php';
// Create an SMTP transport and demand NTLM authentication.
// Username and password must be specified, otherwise no authentication
// will be attempted.
// If NTLM authentication fails, an exception will be thrown.
// See the ezcMailSmtpTransport class for a list of supported methods.
$options = new ezcMailSmtpTransportOptions();
$options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM;
$transport = new ezcMailSmtpTransport('mailhost.example.com', 'username', 'password', null, $options);
// The option can also be specified via the option property:
$transport->options->preferredAuthMethod = ezcMailSmtpTransport::AUTH_NTLM;
// Use the SMTP transport to send the created mail object
$transport->send($mail);
 function sendConfirmationMail($list)
 {
     $tpl = eZTemplate::factory();
     $template = 'design:jaj_newsletter/subscription/mail/confirm.tpl';
     $siteINI = eZINI::instance('site.ini');
     $i18nINI = eZINI::instance('i18n.ini');
     $transport = $siteINI->variable('MailSettings', 'Transport');
     $charset = $i18nINI->variable('CharacterSettings', 'Charset');
     $emailSender = $siteINI->variable('MailSettings', 'EmailSender');
     if (!$emailSender) {
         $emailSender = $siteINI->variable('MailSettings', 'AdminEmail');
     }
     if ($transport == 'SMTP') {
         $mailTransport = new ezcMailSmtpTransport($siteINI->variable('MailSettings', 'TransportServer'), $siteINI->variable('MailSettings', 'TransportUser'), $siteINI->variable('MailSettings', 'TransportPassword'), $siteINI->variable('MailSettings', 'TransportPort'));
     } else {
         eZDebug::writeError('Only SMTP Transport supported', 'jajNewsletterSubscription::sendConfirmationMail');
         throw new Exception('Only SMTP Transport supported');
     }
     $tpl->setVariable('subscription', $this);
     $tpl->setVariable('list', $list);
     $tpl->setVariable('hostname', eZSys::hostname());
     $templateResult = $tpl->fetch($template);
     $subject = "Please confirm your newsletter subscription";
     if ($tpl->hasVariable('subject')) {
         $subject = $tpl->variable('subject');
     }
     $mail = new ezcMailComposer();
     $mail->charset = $charset;
     $mail->subjectCharset = $charset;
     $mail->subject = $subject;
     $mail->plainText = $templateResult;
     $mail->from = ezcMailTools::parseEmailAddress($emailSender, $charset);
     $mail->addTo(new ezcMailAddress($this->Email, $this->Name, $charset));
     $mail->build();
     $mailTransport->send($mail);
 }