/** * Returns the array $items consisting of ezcMailAddress objects * as one RFC822 compliant address string. * * Set foldLength to control how many characters each line can have before a line * break is inserted according to the folding rules specified in RFC2822. * * @param array(ezcMailAddress) $items * @param int $foldLength * @return string */ public static function composeEmailAddresses(array $items, $foldLength = null) { $textElements = array(); foreach ($items as $item) { $textElements[] = ezcMailTools::composeEmailAddress($item); } if ($foldLength === null) { return implode(', ', $textElements); } $result = ""; $charsSinceFold = 0; foreach ($textElements as $element) { $length = strlen($element); if ($charsSinceFold + $length + 2 > $foldLength) { // fold last line if there is any if ($result != '') { $result .= "," . ezcMailTools::lineBreak() . ' '; $charsSinceFold = 0; } $result .= $element; } else { if ($result == '') { $result = $element; } else { $result .= ', ' . $element; } } $charsSinceFold += $length + 1; } return $result; }
/** * Returns the generated headers for the mail. * * This method is called automatically when the mail message is built. * You can re-implement this method in subclasses if you wish to set * different mail headers than ezcMail. * * @return string */ public function generateHeaders() { // set our headers first. if ($this->from !== null) { $this->setHeader("From", ezcMailTools::composeEmailAddress($this->from)); } if ($this->to !== null) { $this->setHeader("To", ezcMailTools::composeEmailAddresses($this->to)); } if (count($this->cc)) { $this->setHeader("Cc", ezcMailTools::composeEmailAddresses($this->cc)); } if (count($this->bcc)) { $this->setHeader("Bcc", ezcMailTools::composeEmailAddresses($this->bcc)); } $this->setHeader('Subject', $this->subject, $this->subjectCharset); $this->setHeader('MIME-Version', '1.0'); $this->setHeader('User-Agent', 'eZ Components'); $this->setHeader('Date', date('r')); $idhost = $this->from != null && $this->from->email != '' ? $this->from->email : 'localhost'; if (is_null($this->messageId)) { $this->setHeader('Message-Id', '<' . ezcMailTools::generateMessageId($idhost) . '>'); } else { $this->setHeader('Message-Id', $this->messageID); } // if we have a body part, include the headers of the body if (is_subclass_of($this->body, "ezcMailPart")) { return parent::generateHeaders() . $this->body->generateHeaders(); } return parent::generateHeaders(); }
public function testReplyToReply() { $mail = new ezcMail(); $mail->addTo(new ezcMailAddress('*****@*****.**', 'Fræderik Hølljen', 'ISO-8859-1')); $address = new ezcMailAddress('*****@*****.**', 'Reply Går', 'ISO-8859-1'); $mail->setHeader('Reply-To', ezcMailTools::composeEmailAddress($address)); // $mail->setHeader( 'Reply-To', '*****@*****.**' ); $reply = ezcMailTools::replyToMail($mail, new ezcMailAddress('*****@*****.**', 'Reply Går', 'ISO-8859-1')); $this->assertEquals($reply->to, array(new ezcMailAddress('*****@*****.**', "Reply GÃ¥r", 'utf-8'))); }
public function testNoDoubleFold() { $composedAddress = ezcMailTools::composeEmailAddress(new ezcMailAddress('*****@*****.**', 'From name ØÆÅ test test test test with a very long name which contains norwegian characters ÆØÅæøÅ', 'utf-8')); $this->assertSame($composedAddress, ezcMailHeaderFolder::foldAny($composedAddress)); }
<?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");