Ver Mensaje Individual
  #12 (permalink)  
Antiguo 24/06/2009, 03:47
una_xikilla
 
Fecha de Ingreso: agosto-2008
Mensajes: 161
Antigüedad: 18 años, 1 mes
Puntos: 0
Respuesta: Error con phpmailer y gmail

Código PHP:
function SmtpClose() {
    if(
$this->smtp != NULL) {
      if(
$this->smtp->Connected()) {
        
$this->smtp->Quit();
        
$this->smtp->Close();
      }
    }
  }

  function 
SetLanguage($lang_type, $lang_path = 'language/') {
    if(
file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
      include(
$lang_path.'phpmailer.lang-'.$lang_type.'.php');
    } elseif (
file_exists($lang_path.'phpmailer.lang-en.php')) {
      include(
$lang_path.'phpmailer.lang-en.php');
    } else {
      
$this->SetError('Could not load language file');
      return 
false;
    }
    
$this->language = $PHPMAILER_LANG;

    return 
true;
  }

  function 
AddrAppend($type, $addr) {
    
$addr_str = $type . ': ';
    
$addr_str .= $this->AddrFormat($addr[0]);
    if(
count($addr) > 1) {
      for(
$i = 1; $i < count($addr); $i++) {
        
$addr_str .= ', ' . $this->AddrFormat($addr[$i]);
      }
    }
    
$addr_str .= $this->LE;

    return 
$addr_str;
  }

  function 
AddrFormat($addr) {
    if(empty(
$addr[1])) {
      
$formatted = $this->SecureHeader($addr[0]);
    } else {
      
$formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
    }

    return 
$formatted;
  }

 function 
WrapText($message, $length, $qp_mode = false) {
    
$soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
    
// If utf-8 encoding is used, we will need to make sure we don't
    // split multibyte characters when we wrap
    
$is_utf8 = (strtolower($this->CharSet) == "utf-8");

    
$message = $this->FixEOL($message);
    if (
substr($message, -1) == $this->LE) {
      
$message = substr($message, 0, -1);
    }

    
$line = explode($this->LE, $message);
    
$message = '';
    for (
$i=0 ;$i < count($line); $i++) {
      
$line_part = explode(' ', $line[$i]);
      
$buf = '';
      for (
$e = 0; $e<count($line_part); $e++) {
        
$word = $line_part[$e];
        if (
$qp_mode and (strlen($word) > $length)) {
          
$space_left = $length - strlen($buf) - 1;
          if (
$e != 0) {
            if (
$space_left > 20) {
              
$len = $space_left;
              if (
$is_utf8) {
                
$len = $this->UTF8CharBoundary($word, $len);
              } elseif (
substr($word, $len - 1, 1) == "=") {
                
$len--;
              } elseif (
substr($word, $len - 2, 1) == "=") {
                
$len -= 2;
              }
              
$part = substr($word, 0, $len);
              
$word = substr($word, $len);
              
$buf .= ' ' . $part;
              
$message .= $buf . sprintf("=%s", $this->LE);
            } else {
              
$message .= $buf . $soft_break;
            }
            
$buf = '';
          }
          while (
strlen($word) > 0) {
            
$len = $length;
            if (
$is_utf8) {
              
$len = $this->UTF8CharBoundary($word, $len);
            } elseif (
substr($word, $len - 1, 1) == "=") {
              
$len--;
            } elseif (
substr($word, $len - 2, 1) == "=") {
              
$len -= 2;
            }
            
$part = substr($word, 0, $len);
            
$word = substr($word, $len);

            if (
strlen($word) > 0) {
              
$message .= $part . sprintf("=%s", $this->LE);
            } else {
              
$buf = $part;
            }
          }
        } else {
          
$buf_o = $buf;
          
$buf .= ($e == 0) ? $word : (' ' . $word);

          if (
strlen($buf) > $length and $buf_o != '') {
            
$message .= $buf_o . $soft_break;
            
$buf = $word;
          }
        }
      }
      
$message .= $buf . $this->LE;
    }

    return 
$message;
  }

  function 
UTF8CharBoundary($encodedText, $maxLength) {
    
$foundSplitPos = false;
    
$lookBack = 3;
    while (!
$foundSplitPos) {
      
$lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
      
$encodedCharPos = strpos($lastChunk, "=");
      if (
$encodedCharPos !== false) {
        
// Found start of encoded character byte within $lookBack block.
        // Check the encoded byte value (the 2 chars after the '=')
        
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
        
$dec = hexdec($hex);
        if (
$dec < 128) { // Single byte character.
          // If the encoded char was found at pos 0, it will fit
          // otherwise reduce maxLength to start of the encoded char
          
$maxLength = ($encodedCharPos == 0) ? $maxLength :
          
$maxLength - ($lookBack - $encodedCharPos);
          
$foundSplitPos = true;
        } elseif (
$dec >= 192) { // First byte of a multi byte character
          // Reduce maxLength to split at start of character
          
$maxLength = $maxLength - ($lookBack - $encodedCharPos);
          
$foundSplitPos = true;
        } elseif (
$dec < 192) { // Middle byte of a multi byte character, look further back
          
$lookBack += 3;
        }
      } else {
        
// No encoded character found
        
$foundSplitPos = true;
      }
    }
    return 
$maxLength;
  }

  function 
SetWordWrap() {
    if(
$this->WordWrap < 1) {
      return;
    }

    switch(
$this->message_type) {
      case 
'alt':
        
/* fall through */
      
case 'alt_attachments':
        
$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
        break;
      default:
        
$this->Body = $this->WrapText($this->Body, $this->WordWrap);
        break;
    }
  }

  function 
CreateHeader() {
    
$result = '';

    
/* Set the boundaries */
    
$uniq_id = md5(uniqid(time()));
    
$this->boundary[1] = 'b1_' . $uniq_id;
    
$this->boundary[2] = 'b2_' . $uniq_id;

    
$result .= $this->HeaderLine('Date', $this->RFCDate());
    if(
$this->Sender == '') {
      
$result .= $this->HeaderLine('Return-Path', trim($this->From));
    } else {
      
$result .= $this->HeaderLine('Return-Path', trim($this->Sender));
    }

    
/* To be created automatically by mail() */
    
if($this->Mailer != 'mail') {
      if(
count($this->to) > 0) {
        
$result .= $this->AddrAppend('To', $this->to);
      } elseif (
count($this->cc) == 0) {
        
$result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
      }
      if(
count($this->cc) > 0) {
        
$result .= $this->AddrAppend('Cc', $this->cc);
      }
    }

    
$from = array();
    
$from[0][0] = trim($this->From);
    
$from[0][1] = $this->FromName;
    
$result .= $this->AddrAppend('From', $from);

    
/* sendmail and mail() extract Cc from the header before sending */
    
if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
      
$result .= $this->AddrAppend('Cc', $this->cc);
    }

    
/* sendmail and mail() extract Bcc from the header before sending */
    
if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
      
$result .= $this->AddrAppend('Bcc', $this->bcc);
    }

    if(
count($this->ReplyTo) > 0) {
      
$result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
    }

    
/* mail() sets the subject itself */
    
if($this->Mailer != 'mail') {
      
$result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
    }

    if(
$this->MessageID != '') {
      
$result .= $this->HeaderLine('Message-ID',$this->MessageID);
    } else {
      
$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
    }
    
$result .= $this->HeaderLine('X-Priority', $this->Priority);
    
$result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');

    if(
$this->ConfirmReadingTo != '') {
      
$result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
    }

    
// Add custom headers
    
for($index = 0; $index < count($this->CustomHeader); $index++) {
      
$result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
    }
    if (!
$this->sign_key_file) {
      
$result .= $this->HeaderLine('MIME-Version', '1.0');
      
$result .= $this->GetMailMIME();
    }

    return 
$result;
  }

  function 
GetMailMIME() {
    
$result = '';
    switch(
$this->message_type) {
      case 
'plain':
        
$result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
        
$result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
        break;
      case 
'attachments':
        
/* fall through */
      
case 'alt_attachments':
        if(
$this->InlineImageExists()){
          
$result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
        } else {
          
$result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
          
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
        }
        break;
      case 
'alt':
        
$result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
        
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
        break;
    }

    if(
$this->Mailer != 'mail') {
      
$result .= $this->LE.$this->LE;
    }

    return 
$result;
  }