Пример #1
0
 /**
  * Sends the mail $mail using the PHP mail method.
  *
  * Note that a message may not arrive at the destination even though
  * it was accepted for delivery.
  *
  * @throws ezcMailTransportException
  *         if the mail was not accepted for delivery by the MTA.
  * @param ezcMail $mail
  */
 public function send(ezcMail $mail)
 {
     $mail->appendExcludeHeaders(array('to', 'subject'));
     $headers = rtrim($mail->generateHeaders());
     // rtrim removes the linebreak at the end, mail doesn't want it.
     if (count($mail->to) + count($mail->cc) + count($mail->bcc) < 1) {
         throw new ezcMailTransportException('No recipient addresses found in message header.');
     }
     $additionalParameters = "";
     if (isset($mail->returnPath)) {
         $additionalParameters = "-f{$mail->returnPath->email}";
     }
     $success = mail(ezcMailTools::composeEmailAddresses($mail->to), $mail->getHeader('Subject'), $mail->generateBody(), $headers, $additionalParameters);
     if ($success === false) {
         throw new ezcMailTransportException('The email could not be sent by sendmail');
     }
 }
Пример #2
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;
 }