Esempio n. 1
0
 /**
  * Returns a new mail object that is a reply to the current object.
  *
  * The new mail will have the correct to, cc, bcc and reference headers set.
  * It will not have any body set.
  *
  * By default the reply will only be sent to the sender of the original mail.
  * If $type is set to REPLY_ALL, all the original recipients will be included
  * in the reply.
  *
  * Use $subjectPrefix to set the prefix to the subject of the mail. The default
  * is to prefix with 'Re: '.
  *
  * @param ezcMail $mail
  * @param ezcMailAddress $from
  * @param int $type REPLY_SENDER or REPLY_ALL
  * @param string $subjectPrefix
  * @param string $mailClass
  * @return ezcMail
  */
 public static function replyToMail(ezcMail $mail, ezcMailAddress $from, $type = self::REPLY_SENDER, $subjectPrefix = "Re: ", $mailClass = "ezcMail")
 {
     $reply = new $mailClass();
     $reply->from = $from;
     // To = Reply-To if set
     if ($mail->getHeader('Reply-To') != '') {
         $reply->to = ezcMailTools::parseEmailAddresses($mail->getHeader('Reply-To'));
     } else {
         $reply->to = array($mail->from);
     }
     if ($type == self::REPLY_ALL) {
         // Cc = Cc + To - your own address
         $cc = array();
         foreach ($mail->to as $address) {
             if ($address->email != $from->email) {
                 $cc[] = $address;
             }
         }
         foreach ($mail->cc as $address) {
             if ($address->email != $from->email) {
                 $cc[] = $address;
             }
         }
         $reply->cc = $cc;
     }
     $reply->subject = $subjectPrefix . $mail->subject;
     if ($mail->getHeader('Message-Id')) {
         // In-Reply-To = Message-Id
         $reply->setHeader('In-Reply-To', $mail->getHeader('Message-ID'));
         // References = References . Message-Id
         if ($mail->getHeader('References') != '') {
             $reply->setHeader('References', $mail->getHeader('References') . ' ' . $mail->getHeader('Message-ID'));
         } else {
             $reply->setHeader('References', $mail->getHeader('Message-ID'));
         }
     } else {
         $reply->setHeader('References', $mail->getHeader('References'));
     }
     return $reply;
 }
Esempio n. 2
0
 public function testParseEmailAddressesLocalEncoding()
 {
     $add = ezcMailTools::parseEmailAddresses('Test äöää<*****@*****.**>, En Lømmel <*****@*****.**>', 'iso-8859-1');
     $this->assertEquals('Test äöää', $add[0]->name);
     $this->assertEquals('*****@*****.**', $add[0]->email);
     $this->assertEquals('En Lømmel', $add[1]->name);
     $this->assertEquals('*****@*****.**', $add[1]->email);
 }
Esempio n. 3
0
 /**
  * Returns an ezcMail corresponding to the parsed message.
  * You can specify an alternate class using the $class parameter, if you
  * extended ezcMail.
  *
  * @param string $class Class to instanciate instead of ezcMail.
  * @return ezcMail
  */
 public function finish($class = "ezcMail")
 {
     $mail = new $class();
     $mail->setHeaders($this->headers->getCaseSensitiveArray());
     ezcMailPartParser::parsePartHeaders($this->headers, $mail);
     // from
     if (isset($this->headers['From'])) {
         $mail->from = ezcMailTools::parseEmailAddress($this->headers['From']);
     }
     // to
     if (isset($this->headers['To'])) {
         $mail->to = ezcMailTools::parseEmailAddresses($this->headers['To']);
     }
     // cc
     if (isset($this->headers['Cc'])) {
         $mail->cc = ezcMailTools::parseEmailAddresses($this->headers['Cc']);
     }
     // bcc
     if (isset($this->headers['Bcc'])) {
         $mail->bcc = ezcMailTools::parseEmailAddresses($this->headers['Bcc']);
     }
     // subject
     if (isset($this->headers['Subject'])) {
         $mail->subject = ezcMailTools::mimeDecode($this->headers['Subject']);
         $mail->subjectCharset = 'utf-8';
     }
     // message ID
     if (isset($this->headers['Message-Id'])) {
         $mail->messageID = $this->headers['Message-Id'];
     }
     // Return-Path
     if (isset($this->headers['Return-Path'])) {
         $mail->returnPath = ezcMailTools::parseEmailAddress($this->headers['Return-Path']);
     }
     if ($this->bodyParser !== null) {
         $mail->body = $this->bodyParser->finish();
     }
     return $mail;
 }
Esempio n. 4
0
<?php

require_once 'tutorial_autoload.php';
$mailAddresses = array(new ezcMailAddress('*****@*****.**', 'Jøhn Doe', 'ISO-8859-1'), new ezcMailAddress('*****@*****.**', 'Jane Doe'));
$addresses = '=?ISO-8859-1?B?SsO4aG4gRG9l?= <*****@*****.**>, Jane Doe <*****@*****.**';
// Convert ezcMailAddress to string representation
var_dump(ezcMailTools::composeEmailAddress($mailAddresses[0]));
var_dump(ezcMailTools::composeEmailAddresses($mailAddresses));
// Convert string to ezcMailAddress
var_dump(ezcMailTools::parseEmailAddress($addresses));
var_dump(ezcMailTools::parseEmailAddresses($addresses));
// Validate an email address (with a regular expression, without checking for MX records)
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**');
// Validate an email address with MX records check.
// MX record checking does not work on Windows due to the lack of getmxrr()
// and checkdnsrr() PHP functions. The ezcBaseFunctionalityNotSupportedException
// is thrown in this case.
// set this to your mail server, it is used in a
// 'HELO SMTP' command to validate against MX records
ezcMailTools::$mxValidateServer = 'your.mail.server';
// set this to a mail address such as '*****@*****.**', it is used in a
// 'MAIL FROM' SMTP command to validate against MX records
ezcMailTools::$mxValidateAddress = '*****@*****.**';
$isValid = ezcMailTools::validateEmailAddress('*****@*****.**', true);
// Create a new mail object
$mail = new ezcMail();
$mail->from = $mailAddresses[1];
$mail->addTo($mailAddresses[0]);
$mail->subject = "Top secret";
// Use the lineBreak() method
$mail->body = new ezcMailText("Confidential" . ezcMailTools::lineBreak() . "DO NOT READ");