コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: ezmail_test.php プロジェクト: CG77/ezpublish-legacy
 /**
  * @dataProvider providerTestExtractEmail
  */
 public function testExtractEmail($recipient, $name, $email)
 {
     eZMail::extractEmail($recipient, $extractedEmail, $extractedName);
     self::assertEquals($extractedEmail, $email);
     self::assertEquals($extractedName, $name);
 }
コード例 #3
0
$time_start = microtime_float2();
$smtp = getConnection($active_server, $serverlist);
$allowPersistent = $mailSettings->variable('SMTPClusterSettings', 'PersistentConnection') == 'enabled' ? true : false;
for ($i = 0; $i < count($mailFiles); $i++) {
    // sending message
    $email = file_get_contents($mailFiles[$i]);
    $lines = file($mailFiles[$i]);
    // get from and to
    $regex = regexEmail();
    $expression = "/({$regex})/";
    preg_match_all($expression, $lines[1], $matches);
    $from_address = array_pop($matches[1]);
    preg_match_all($expression, $lines[7], $matches);
    $to_address = array_pop($matches[1]);
    eZMail::extractEmail($from_address, $from, $name);
    eZMail::extractEmail($to_address, $to, $name);
    if (eZMail::validate($from) && eZMail::validate($to)) {
        if ($smtp->send($from, $to, $email)) {
            $cli->output(".", false);
            // rename file on hdd
            eZFile::rename($mailFiles[$i], $mailFiles[$i] . ".send");
            if (!$allowPersistent) {
                $smtp->quit();
                $smtp = getConnection($active_server, $serverlist);
            }
        } else {
            if (count($serverlist) > 1) {
                // retrying other server
                $active_server = nextConnection($active_server, $serverlist, $i + 1);
                $smtp = getConnection($active_server, $serverlist);
                $try = 1;
コード例 #4
0
function unsubscribe($address_string, $list_name)
{
    $subscription_list = eZSubscriptionList::fetch($list_name);
    eZMail::extractEmail($address_string, $email, $name);
    if ($email) {
        $subscription = eZSubscription::fetchByEmailSubscriptionListID($email, $subscription_list->attribute('id'));
        if ($subscription) {
            if ($subscription->attribute('status') == eZSubscription::StatusApproved) {
                $subscription->setAttribute('status', eZSubscription::StatusRemovedSelf);
                $subscription->sync();
                return $subscription;
            }
        }
    }
    return false;
}