Ver Mensaje Individual
  #6 (permalink)  
Antiguo 06/04/2007, 13:51
infocharly84
 
Fecha de Ingreso: abril-2007
Mensajes: 1
Antigüedad: 17 años
Puntos: 0
Sonrisa Re: Header error al redireccionar

Hola, el problema que tienes creo que se resuelve poniendo bien las funciones:
ob_start() y ob_end_flush(), la primera tienes que ponerla al comienzo del codigo, para que inhabilite el envio de informacion al cliente, guardandola en un buffer, y la segunda justo despues de la funcion header(), para envie la informacion. Todo esto es porque la funcion header(), no funciona despues de que se ha enviado informacion al cliente. BUeno yo tenia exactamente el mismo problema que tu, y lo solucione asi. Te quedaria asi:

<?php
ob_start();
include("includes/config.php");
include("includes/class.phpmailer.php");

// Primero comprobamos que ningún campo esté vacío y que todos los campos existan.
if(isset($_POST['username']) && !empty($_POST['username']) &&
isset($_POST['password']) && !empty($_POST['password']) &&
isset($_POST['realname']) && !empty($_POST['realname']) &&
isset($_POST['empresa']) && !empty($_POST['empresa']) &&
isset($_POST['ciudad']) && !empty($_POST['ciudad']) &&
isset($_POST['provincia']) && !empty($_POST['provincia']) &&
isset($_POST['cpostal']) && !empty($_POST['cpostal']) &&
isset($_POST['telefono']) && !empty($_POST['telefono']) &&
isset($_POST['email']) && !empty($_POST['email']))
{
// Si entramos es que todo se ha realizado correctamente
$link = Conectarse();
//$link = mysql_connect("localhost","usuario","contraseña");
mysql_select_db("xxxxxxx",$link);

// Con esta sentencia SQL insertaremos los datos en la base de datos
mysql_query("INSERT INTO phpauthent_users (username,password,realname,empresa,ciudad,provinc ia,cpostal,telefono,email) VALUES ('{$_POST['username']}','{$_POST['password']}','{$_POST['realname']}','{$_POST['empresa']}','{$_POST['ciudad']}','{$_POST['provincia']}','{$_POST['cpostal']}','{$_POST['telefono']}','{$_POST['email']}')",$link);

// Ahora comprobaremos que todo ha ido correctamente
$my_error = mysql_error($link);

if(!empty($my_error)) {

echo "Ha habido un error al insertar los valores.<br>$my_error";

} else {

/*------------------------------------envio del mail a los socios-------------------------------------*/

$mail = new PHPMailer();

$mail->From = "[email protected]";
$mail->FromName = "xxxxxxxxxx";
$mail->Host = "smtp.xxxxxxxxx.com";
$mail->Subject = "Alta de usuario";
$mail->Mailer = "smtp";

// HTML body
$body = "<font face=\"Arial, Helvetica, sans-serif\" size=\"2\">Hola <b>" . $_POST["nombre"] . "</b><p>";
$body .= "Grácias por suscribirse a xxxxxxxx.<p>";
$body .= "<b>Nombre: </b>" .$_POST['realname']."<br>";
$body .= "<b>Empresa: </b>" .$_POST['empresa']."<br>";
$body .= "<b>Ciudad: </b>" .$_POST['ciudad']."<br>";
$body .= "<b>Provincia: </b>" .$_POST['provincia']."<br>";
$body .= "<b>C.Postal: </b>" .$_POST['cpostal']."<br>";
$body .= "<b>Telefono: </b>" .$_POST['telefono']."<br>";
$body .= "<b>E-mail: </b>" .$_POST['mail']."<br>";
$body .= "<b>Usuario: </b>" .$_POST['username']."<br>";
$body .= "<b>Clave: </b>" .$_POST['password']."<p>";
$body .= "Atentamente, <br>";
$body .= "<b>xxxxxxxxxx lista de correo<b>";

// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hola " . $row["nombre"] . ", \n\n";
$text_body .= "Grácias por suscribirse a xxxxxxxxxx.\n\n";
$text_body .= "Nombre: " .$_POST['realname']. "\n";
$text_body .= "Empresa: " .$_POST['empresa']. "\n";
$text_body .= "Ciudad: " .$_POST['ciudad']. "\n";
$text_body .= "Provincia: " .$_POST['provincia']. "\n";
$text_body .= "C.Postal: " .$_POST['cpostal']. "\n";
$text_body .= "Telefono: " .$_POST['telefono']. "\n";
$text_body .= "E-mail: " .$_POST['email']. "\n";
$text_body .= "Usuario: " .$_POST['username']. "\n";
$text_body .= "Clave: " .$_POST['password']. "\n\n";
$text_body .= "Atentamente, \n";
$text_body .= "xxxxxxxxx lista de correo</font>";

$mail->Body = $body;
$mail->AltBody = $text_body;
// $mail->AddAddress($row["mail"], $row["empresa"]);
$mail->AddAddress($_POST["email"], $_POST["empresa"]);
// $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

if(!$mail->Send())
echo "Ha habido algún error enviando el mensaje a " . $_POST["email"] . "<br>";

// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
} else {
echo "Error, no ha introducido todos los datos";
}

header ("Location: index.php?gracias.php");
ob_end_flush();
?>