get7BitEncoding() public static method

Get the Encoder that provides 7-bit encoding.
public static get7BitEncoding ( ) : Swift_Mime_ContentEncoder
return Swift_Mime_ContentEncoder
 public function initialize()
 {
     $this->setMailer(sfContext::getInstance()->getMailer());
     mb_language('Ja');
     $this->message = Swift_Message::newInstance();
     $this->message->getHeaders()->remove('Subject');
     $subjectHeader = new kzl_Jp_Swift_Mime_Headers_UnstructuredHeader('Subject', new Swift_Mime_HeaderEncoder_Base64HeaderEncoder());
     $this->message->getHeaders()->set($subjectHeader);
     $this->message->setContentType('text/plain');
     $this->setCharset('iso-2022-jp');
     $this->message->setEncoder(Swift_Encoding::get7BitEncoding());
 }
 public function testGet7BitEncodingReturns7BitEncoder()
 {
     $encoder = Swift_Encoding::get7BitEncoding();
     $this->assertEqual('7bit', $encoder->getName());
 }
Beispiel #3
0
 /**
  * Swiftのメッセージオブジェクトを返す
  *
  * @param String $subject
  * @param Array $from
  * @param String $body
  * @return Object
  * @codeCoverageIgnore
  */
 public function setMessage($subject, $from, $body)
 {
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setBody($body);
     $message->setCharset($this->charset);
     $message->setEncoder(\Swift_Encoding::get7BitEncoding());
     $this->message = $message;
     $this->setReturnPath();
     $this->addTextHeader('X-Original-To');
     return $message;
 }
 function sendMail($smtp_server, $to, $from, $subject, $body, $cc, $bcc, $attachments = null, $smtp_port = 25, $smtp_username = null, $smtp_password = '', $type = 'text/plain', $transport = 0, $message_id = null, $in_reply_to = null, $inline_images = null, &$complete_mail, $att_version)
 {
     //Load in the files we'll need
     Env::useLibrary('swift');
     try {
         $mail_transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_port, $transport);
         $smtp_authenticate = $smtp_username != null;
         if ($smtp_authenticate) {
             $mail_transport->setUsername($smtp_username);
             $mail_transport->setPassword(self::ENCRYPT_DECRYPT($smtp_password));
         }
         $mailer = Swift_Mailer::newInstance($mail_transport);
         // init Swift logger
         if (defined('LOG_SWIFT') && LOG_SWIFT > 0) {
             $swift_logger = new Swift_Plugins_Loggers_ArrayLogger();
             $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($swift_logger));
             $swift_logger_level = LOG_SWIFT;
             // 0: no log, 1: log only errors, 2: log everything
         } else {
             $swift_logger_level = 0;
         }
         if (is_string($from)) {
             $pos = strrpos($from, "<");
             if ($pos !== false) {
                 $sender_name = trim(substr($from, 0, $pos));
                 $sender_address = str_replace(array("<", ">"), array("", ""), trim(substr($from, $pos, strlen($from) - 1)));
             } else {
                 $sender_name = "";
                 $sender_address = $from;
             }
             $from = array($sender_address => $sender_name);
         }
         //Create a message
         $message = Swift_Message::newInstance($subject)->setFrom($from)->setContentType($type);
         $to = self::prepareEmailAddresses($to);
         $cc = self::prepareEmailAddresses($cc);
         $bcc = self::prepareEmailAddresses($bcc);
         foreach ($to as $address) {
             $message->addTo(array_var($address, 0), array_var($address, 1, ""));
         }
         foreach ($cc as $address) {
             $message->addCc(array_var($address, 0), array_var($address, 1, ""));
         }
         foreach ($bcc as $address) {
             $message->addBcc(array_var($address, 0), array_var($address, 1, ""));
         }
         if ($in_reply_to) {
             if (str_starts_with($in_reply_to, "<")) {
                 $in_reply_to = substr($in_reply_to, 1, -1);
             }
             $validator = new SwiftHeaderValidator();
             if ($validator->validate_id_header_value($in_reply_to)) {
                 $message->getHeaders()->addIdHeader("In-Reply-To", $in_reply_to);
             }
         }
         if ($message_id) {
             if (str_starts_with($message_id, "<")) {
                 $message_id = substr($message_id, 1, -1);
             }
             $message->setId($message_id);
         }
         // add attachments
         if (is_array($attachments)) {
             foreach ($attachments as $att) {
                 if ($att_version < 2) {
                     $swift_att = Swift_Attachment::newInstance($att["data"], $att["name"], $att["type"]);
                 } else {
                     $swift_att = Swift_Attachment::fromPath($att['path'], $att['type']);
                     $swift_att->setFilename($att["name"]);
                 }
                 if (substr($att['name'], -4) == '.eml') {
                     $swift_att->setEncoder(Swift_Encoding::get7BitEncoding());
                     $swift_att->setContentType('message/rfc822');
                 }
                 $message->attach($swift_att);
             }
         }
         // add inline images
         if (is_array($inline_images)) {
             foreach ($inline_images as $image_url => $image_path) {
                 $cid = $message->embed(Swift_Image::fromPath($image_path));
                 $body = str_replace($image_url, $cid, $body);
             }
         }
         self::adjustBody($message, $type, $body);
         $message->setBody($body);
         //Send the message
         $complete_mail = self::retrieve_original_mail_code($message);
         $result = $mailer->send($message);
         if ($swift_logger_level >= 2 || $swift_logger_level > 0 && !$result) {
             file_put_contents(CACHE_DIR . "/swift_log.txt", "\n" . gmdate("Y-m-d H:i:s") . " DEBUG:\n" . $swift_logger->dump() . "----------------------------------------------------------------------------", FILE_APPEND);
             $swift_logger->clear();
         }
         return $result;
     } catch (Exception $e) {
         Logger::log("ERROR SENDING EMAIL: " . $e->getTraceAsString(), Logger::ERROR);
         //if there is an error with the connection, let the user know about it
         $mail_error = $e->getMessage();
         $mail_error = stristr($mail_error, 'Log data:', true);
         flash_error(lang('mail not sent') . " '" . $mail_error . "'");
         if ($swift_logger_level > 0) {
             $dump = $swift_logger->dump();
             if ($dump != '') {
                 file_put_contents(CACHE_DIR . "/swift_log.txt", "\n" . gmdate("Y-m-d H:i:s") . " DEBUG:\n" . $dump . "----------------------------------------------------------------------------", FILE_APPEND);
                 $swift_logger->clear();
             }
         }
         throw $e;
     }
 }
 private function getEncoder(Email\Part $part)
 {
     $encoding = $part->getEncoding();
     if (null === $encoding) {
         return null;
     }
     switch ($encoding) {
         case Email::ENCODING_BASE64:
             return \Swift_Encoding::getBase64Encoding();
         case Email::ENCODING_QUOTED_PRINTABLE:
             return \Swift_Encoding::getQpEncoding();
         case Email::ENCODING_8BIT:
             return \Swift_Encoding::get8BitEncoding();
         case Email::ENCODING_7BIT:
             return \Swift_Encoding::get7BitEncoding();
         case Email::ENCODING_RAW:
             return new \Swift_Mime_ContentEncoder_RawContentEncoder();
         default:
             throw new \InvalidArgumentException('Unknown encoding "' . $encoding . '"');
     }
 }
Beispiel #6
0
 //instanzio l'oggetto messaggio
 $msg = Swift_Message::newInstance();
 //Give the message a subject
 $msg->setSubject($subject);
 //Set the From address with an associative array
 $msg->setFrom(array($email => $mail_name));
 //set bounce address
 $msg->setReturnPath($bounce_email);
 //set characterset
 $msg->setCharset('utf-8');
 //set content-type
 $msg->setContentType("text/html");
 //Give it a body
 $msg->setBody(stripslashes($msgtxt));
 //set encoder
 $msg->setEncoder(Swift_Encoding::get7BitEncoding());
 $search = array(';', ',,', ',');
 $replace = array('', '', '');
 $msgok = 0;
 while ($row = mysqli_fetch_assoc($result)) {
     //per ogni riga sul db
     if ($row['mail'] != '') {
         $destinatari_raw = $row['mail'];
         //prendo l'id utente
         $id_utente = $row['id'];
         //pulitura indirizzi sostituisco gli spazi e i ";" con le ","
         //$destinatari = str_replace($search, $replace, $destinatari_raw);
         $destinatari = trim($destinatari_raw);
         //https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Validate.php
         if (!Swift_Validate::email($destinatari)) {
             //validate email
Beispiel #7
0
    /**
     * Specifies the encoding scheme in the message.
     *
     * @param string $encoding
     *
     * @return $this
     * @throws SwiftMailerException
     */
    public function setContentTransferEncoding($encoding)
    {
        switch ($encoding) {
            case '7bit':
                $encoder = \Swift_Encoding::get7BitEncoding();
                break;
            case '8bit':
                $encoder = \Swift_Encoding::get8BitEncoding();
                break;
            case 'base64':
                $encoder = \Swift_Encoding::getBase64Encoding();
                break;
            case 'qp':
                $encoder = \Swift_Encoding::getQpEncoding();
                break;
            default:
                throw new SwiftMailerException('Invalid encoding name provided.
												Valid encodings are [7bit, 8bit, base64, qp].');
                break;
        }
        $this->message->setEncoder($encoder);
        return $this;
    }
 /**
  * Swiftのメッセージオブジェクトを返す
  *
  * @param String $subject
  * @param Array $from
  * @param String $body
  * @return Object
  * @codeCoverageIgnore
  */
 public function setMessage($subject, $from, $body)
 {
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setBody($body);
     $message->setCharset($this->charset);
     $message->setEncoder(\Swift_Encoding::get7BitEncoding());
     return $message;
 }