Foros del Web » Programando para Internet » PHP »

El subject llega sin acentos y sin 'ñ'

Estas en el tema de El subject llega sin acentos y sin 'ñ' en el foro de PHP en Foros del Web. Hola amigos !!! Creo que este es un problema para los expertos ! Os esplicaré a ver si alguién tiene la solución Resulta que mi ...
  #1 (permalink)  
Antiguo 05/08/2004, 14:52
 
Fecha de Ingreso: mayo-2002
Ubicación: Toluca
Mensajes: 229
Antigüedad: 21 años, 11 meses
Puntos: 2
Pregunta El subject llega sin acentos y sin 'ñ'

Hola amigos !!!
Creo que este es un problema para los expertos !
Os esplicaré a ver si alguién tiene la solución

Resulta que mi desde mi aplicación envío mail al usuario. Tengo dos maneras de enviarlo. Cuando lo envío com mail() todo es perfecto !!! no tengo error.
Pero alguna vez mi administrador del server, me dijo que tendría que salir autenticados mis mails y me pasó una clase para conectarme al server de envíos de correos y autenticarme para que mis correos salieran seguros, entonces yo mismo hice una función llamada mailer(). Pues resulta que cuando saco correos desde mailer(), los encabezados como el subject y el From llegan sin acentos ni 'ñ' .... el cuerpo del mail llega bien, pero los encabezados no.... que pude ser ???
me imagino que es el server, pero no lo se a ciencia cierta.... podrían ayudarme ???

el código de mailer() trabaja con un archivo que es la 'clase' class.smtp.inc
yo mando mis mails asi:
mailer("[email protected]", "Test envío", Hacer caso omiso a éste coreeo.");

y la funcion es mas o menos así
function mailer($to, $subject, $body){
$params['host'] = 'mail.server.com'; // The smtp server host/ip
$params['port'] = 25; // The smtp server port
$params['helo'] = exec('mail.server.com'); // What to use when sending the helo command. Typically, your domain/hostname
$params['auth'] = TRUE; // Whether to use basic authentication or not
$params['user'] = '[email protected]'; // Username for authentication
$params['pass'] = 'mipass'; // Password for authentication
$number=substr_count($to, ",");
if($number > '0'){
$a_mails = explode(',',$to);
$a_mailsLen = count($a_mails);
for($i=0;$i < $a_mailsLen;$i++){
$send_params['recipients'][$i] = $a_mails[$i];
}
}
}else{
$send_params['recipients'] = array( $to, '[email protected]' );
}

$send_params['headers'] = array( 'Content-type:text/plain', 'From: "YO" <[email protected]>', 'To: '.$to, 'Subject: '.$subject.'');

$send_params['from'] = '[email protected]';
$send_params['body'] = $body;

if(is_object($smtp = smtp::connect($params)) AND $smtp->send($send_params)){
$msg = "\n<table border=0><tr>";
$msg .= "\n<td>OK</td><td>$ead</td><td>".$send_params['recipients'][0]."</td>";
$msg .= "\n</tr></table>";
}else{
$msg = "\n<table border=0><tr>";
$msg .= "\n<td>BAD</td><td>$ead</td><td>".$send_params['recipients'][0]."</td>";
$msg .= "\n</tr></table>";
}
return $msg;
}

TODOS los correos que mando con esta función llegan con headers sin acentos ni ñ.... por favor ayudenme !!!
creo que el error debe estar del lado del server donde me conecto para enviar los mails, ustedes que opinan ????
como lo puedo solucionar???

mil gracias !!!
  #2 (permalink)  
Antiguo 05/08/2004, 15:12
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues no sé com procesa las cabeceras HTTP esa tal "class.smtp.inc" (podrías poner el código o dar referencia de donde está).

En tal caso yo uso PHP Mailer (http://phpmailer.sourceforge.net) para gestionar todo tipo de e-mail (por SMTP directo) .. Permite autentificación para SMTP, adjuntar archivos .. etc ...

Pruebala y nos comentas (no recuerdo haber tenido problemas con acentos o ñ's ..)

Un saludo,
  #3 (permalink)  
Antiguo 05/08/2004, 15:54
 
Fecha de Ingreso: mayo-2002
Ubicación: Toluca
Mensajes: 229
Antigüedad: 21 años, 11 meses
Puntos: 2
No se si sirva de algo poner el código es muy largo .. pero bueno .. de todas formas lo comparto con todos ustedes y más aún contigo Cluster :o)
espero podamos saber que pasa ... de todas formas checaré ese PHPMAILER !!!

Saludos !!!

<?php
set_time_limit (60);
/***************************************
** Filename.......: class.smtp.inc
** Project........: SMTP Class
** Version........: 1.00b
** Last Modified..: 30 September 2001
***************************************/

define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
define('SMTP_STATUS_CONNECTED', 2, TRUE);

class smtp{

var $connection;
var $recipients;
var $headers;
var $timeout;
var $errors;
var $status;
var $body;
var $from;
var $host;
var $port;
var $helo;
var $auth;
var $user;
var $pass;

/***************************************
** Constructor function. Arguments:
** $params - An assoc array of parameters:
**
** host - The hostname of the smtp server Default: localhost
** port - The port the smtp server runs on Default: 25
** helo - What to send as the HELO command Default: localhost
** (typically the hostname of the
** machine this script runs on)
** auth - Whether to use basic authentication Default: FALSE
** user - Username for authentication Default: <blank>
** pass - Password for authentication Default: <blank>
** timeout - The timeout in seconds for the call Default: 5
** to fsockopen()
***************************************/

function smtp($params = array()){

if(!defined('CRLF'))
define('CRLF', "\r\n", TRUE);

$this->timeout = 5;
$this->status = SMTP_STATUS_NOT_CONNECTED;
$this->host = 'localhost';
$this->port = 25;
$this->helo = 'localhost';
$this->auth = FALSE;
$this->user = 'user@[ip]';
$this->pass = 'pass';
$this->errors = array();

foreach($params as $key => $value){
$this->$key = $value;
}
}

/***************************************
** Connect function. This will, when called
** statically, create a new smtp object,
** call the connect function (ie this function)
** and return it. When not called statically,
** it will connect to the server and send
** the HELO command.
***************************************/

function connect($params = array()){

if(!isset($this->status)){
$obj = new smtp($params);
if($obj->connect()){
$obj->status = SMTP_STATUS_CONNECTED;
}

return $obj;

}else{
$this->connection = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
socket_set_timeout($this->connection, 0, 250000);

$greeting = $this->get_data();
if(is_resource($this->connection)){
return $this->auth ? $this->ehlo() : $this->helo();
}else{
$this->errors[] = 'Failed to connect to server: '.$errstr;
return FALSE;
}
}
}

/***************************************
** Function which handles sending the mail.
** Arguments:
** $params - Optional assoc array of parameters.
** Can contain:
** recipients - Indexed array of recipients
** from - The from address. (used in MAIL FROM:),
** this will be the return path
** headers - Indexed array of headers, one header per array entry
** body - The body of the email
** It can also contain any of the parameters from the connect()
** function
***************************************/

function send($params = array()){

foreach($params as $key => $value){
$this->set($key, $value);
}

if($this->is_connected()){

// Do we auth or not? Note the distinction between the auth variable and auth() function
if($this->auth){
if(!$this->auth())
return FALSE;
}

$this->mail($this->from);
if(is_array($this->recipients))
foreach($this->recipients as $value)
$this->rcpt($value);
else
$this->rcpt($this->recipients);

if(!$this->data())
return FALSE;

// Transparency
$headers = str_replace(CRLF.'.', CRLF.'..', trim(implode(CRLF, $this->headers)));
$body = str_replace(CRLF.'.', CRLF.'..', $this->body);
$body = $body[0] == '.' ? '.'.$body : $body;

$this->send_data($headers);
$this->send_data('');
$this->send_data($body);
$this->send_data('.');

return (substr(trim($this->get_data()), 0, 3) === '250');
}else{
$this->errors[] = 'Not connected!';
return FALSE;
}
}

/***************************************
** Function to implement HELO cmd
***************************************/

function helo(){
if(is_resource($this->connection)
AND $this->send_data('HELO '.$this->helo)
AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){
return TRUE;

}else{
$this->errors[] = 'HELO command failed, output: ' . trim(substr(trim($error),3));
return FALSE;
}
}

/***************************************
** Function to implement EHLO cmd
***************************************/

function ehlo(){
if(is_resource($this->connection)
AND $this->send_data('EHLO '.$this->helo)
AND substr(trim($error = $this->get_data()), 0, 3) === '250' ){

return TRUE;

}else{
$this->errors[] = 'EHLO command failed, output: ' . trim(substr(trim($error),3));
return FALSE;
}
}

/***************************************
** Function to implement AUTH cmd
***************************************/

function auth(){
if(is_resource($this->connection)
AND $this->send_data('AUTH LOGIN')
AND substr(trim($error = $this->get_data()), 0, 3) === '334'
AND $this->send_data(base64_encode($this->user)) // Send username
AND substr(trim($error = $this->get_data()),0,3) === '334'
AND $this->send_data(base64_encode($this->pass)) // Send password
AND substr(trim($error = $this->get_data()),0,3) === '235' ){

return TRUE;

}else{
$this->errors[] = 'AUTH command failed: ' . trim(substr(trim($error),3));
return FALSE;
}
}

/***************************************
** Function that handles the MAIL FROM: cmd
***************************************/

function mail($from){

if($this->is_connected()
AND $this->send_data('MAIL FROM:<'.$from.'>')
AND substr(trim($this->get_data()), 0, 2) === '250' ){

return TRUE;

}else
return FALSE;
}

/***************************************
** Function that handles the RCPT TO: cmd
***************************************/

function rcpt($to){

if($this->is_connected()
AND $this->send_data('RCPT TO:<'.$to.'>')
AND substr(trim($error = $this->get_data()), 0, 2) === '25' ){

return TRUE;

}else{
$this->errors[] = trim(substr(trim($error), 3));
return FALSE;
}
}

/***************************************
** Function that sends the DATA cmd
***************************************/

function data(){

if($this->is_connected()
AND $this->send_data('DATA')
AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){

return TRUE;

}else{
$this->errors[] = trim(substr(trim($error), 3));
return FALSE;
}
}

/***************************************
** Function to determine if this object
** is connected to the server or not.
***************************************/

function is_connected(){

return (is_resource($this->connection) AND ($this->status === SMTP_STATUS_CONNECTED));
}

/***************************************
** Function to send a bit of data
***************************************/

function send_data($data){

if(is_resource($this->connection)){
return fwrite($this->connection, $data.CRLF, strlen($data)+2);
}else
return FALSE;
}

/***************************************
** Function to get data.
***************************************/

function &get_data(){

$return = '';
$line = '';

if(is_resource($this->connection)){
while(strpos($return, CRLF) === FALSE OR substr($line,3,1) !== ' '){
$line = fgets($this->connection, 512);
$return .= $line;
}
return $return;

}else
return FALSE;
}

/***************************************
** Sets a variable
***************************************/

function set($var, $value){

$this->$var = $value;
return TRUE;
}

} // End of class
?>
  #4 (permalink)  
Antiguo 05/08/2004, 20:00
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
mm No conozco bien en profundidad el protocolo SMTP .. pero tal vez sea necesario codificar tus datos para que no tengas problemas con "ñ's", acentos y demás caracteres no "ISO nosecuantos" ...

Prueba con funciones como urlencode() .. o utf8_encode() ..

Realmente no sé que codificación será la que necesites .. pero alguna tendrá que ser .. recuerda que los de habla inglesa no usan la "ñ" y el protocolo SMTP no lo inventó un hispanoparalante.

Un saludo,
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:27.