Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/04/2007, 06:04
jormaz
 
Fecha de Ingreso: enero-2007
Mensajes: 19
Antigüedad: 17 años, 3 meses
Puntos: 0
Header error al redireccionar

Hola foro estoy creando un formulario que se inserta en base de datos y después se envía por correo al usuario. El problema que tengo es que al redireccionar la página principal me da este error uqe he probado de subsanar poniendo las variables ob_start() y ob_end_flush(); y no ha funcionado, también he mirado de no dejar espacios y he movido los echo de errores de sitio sin éxito...no se me ocurre nada más, álguien puede echarme una mano, grácias :)

éste es el código:
Código PHP:
<?php
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,provincia,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";
    }
    
ob_start();  
    
header ("Location: index.php?gracias.php");
    
ob_end_flush();  
?>