Page 1 sur 1

problème de redirection

Posté : 04 janv. 2012, 16:51
par mars77
Bonjour,

J'ai créé une page ou j'envoie de information via un mail. Tout se passe tiptop, mais quand je veux rediriger sur la page de confirmation rien ne se passe.
<?php header( 'content-type: text/html; charset=utf-8' );
session_start();
?> 
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>PHPMailer - SMTP basic test with authentication</title>
</head>
<body>
<?php
if(empty($_POST['nom']) ||  empty($_POST['prenom']) || empty($_POST['adresse']) || empty($_POST['npa'])|| empty($_POST['ville'])|| empty($_POST['email']) )
{
echo'<table align="center" width="1000">
<tr><td class="bodycentre"align="center" class="texte" valign="middle"  >';
echo'<br><br><br><br><br><br><samp class="texte" > ATTENTION seule le champ note peux rester vide!&nbsp;</span><a href="javascript:history.back();">Retour au formulaire </a>';
echo'
</td></tr>
<tr><td class="texte" colspan="2">
<hr class="texte">Site optimisé pour Safari.<br>
© 2011 Graphisme : Valentina Zofra et Sarah Richoux / Codage : Martial Croisier<br>
Contact : <a href="mailto:[email protected]" class="lien">Webmaster</a> / <a href="mailto:[email protected]" class="lien">Informations</a><br>
</td></tr></table>';
}
elseif($_SESSION['code'] != $_POST['verif'])  {
	echo'<table align="center" width="1000">
<tr><td class="bodycentre"align="center" class="texte" valign="middle"  >';
echo'<br><br><br><br><br><br><span class="texte"> ATTENTION le code sécurité est faux!</span> <a href="javascript:history.back();" class="bleu">Retour au formulaire </a>';
echo'
</td></tr>
<tr><td class="texte" colspan="2">
<hr class="texte">Site optimisé pour Safari.<br>
© 2011 Graphisme : Valentina Zofra et Sarah Richoux / Codage : Martial Croisier<br>
Contact : <a href="mailto:[email protected]" class="lien">Webmaster</a> / <a href="mailto:[email protected]" class="lien">Informations</a><br>
</td></tr></table>';
 }
else
{
//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('phpmailer/class.phpmailer.php');
//include("phpmailer/examples/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = ('Bonjour &nbsp;'.$_POST['nom'].'&nbsp;'.$_POST['prenom'].",<br><br>Vous venez de passer la commande suivante via le Shop des Kamikazes.<br><br>
 CD New Born :&nbsp;<strong>".$_POST['new']."</strong>&nbsp;fois<br><br>
 CD Show Must Go On :&nbsp;<strong>".$_POST['show']."</strong>&nbsp;fois<br><br>
 CD X :&nbsp;<strong>".$_POST['X'].
"</strong>&nbsp;fois<br><br>Prix total de la commande :&nbsp;<strong>".$_POST['prix'].
"Frs</strong><br><br><strong> Livraison et facturation:</strong><br><br>
 Nom &nbsp;Prénom:&nbsp;".$_POST['nom'].'&nbsp;'.$_POST['prenom']."<br><br>
Adresse :&nbsp;".$_POST['adresse']."<br><br>
NPA&nbsp;Ville:&nbsp;".$_POST['npa'].'&nbsp;'.$_POST['ville']."<br><br>
Email:&nbsp;".$_POST['email']."<br><br>
Note &nbsp;".$_POST['note']."<br>"
);
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.netplus.ch"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.netplus.ch"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]"; // SMTP account username
$mail->Password   = "77srammars77";        // SMTP account password

$mail->SetFrom(''.$_POST['email'].'', ''.$_POST['nom'].''.$_POST['prenom'].'');

$mail->AddReplyTo(''.$_POST['email'].'',''.$_POST['nom'].''.$_POST['prenom'].'');

$mail->Subject    = "Voici une nouvelle commande depuis le shop des Kamikazes";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address);
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {

header("location:shopconfirme.php");
}

}


?>

</body>
</html>
Normalement cela fonction bien avec se genre de code
header("location:shopconfirme.php");
Merci a celui qui pourra m'aider

Re: problème de redirection

Posté : 04 janv. 2012, 17:10
par Mazarini
A priori, il faut mettre :
error_reporting(E_ALL | E_STRICT);
et tu auras un message comme quoi il ne faut pas faire de header après le début des output.

Le problème vient de :
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
<title>PHPMailer - SMTP basic test with authentication</title>
</head>
<body>
qu'il faut mettre après le if.

Re: problème de redirection

Posté : 04 janv. 2012, 17:24
par mars77
J'ai modifier mon code comme ceci:
<?php header( 'content-type: text/html; charset=utf-8' );
session_start();
?> 
<?php
if(empty($_POST['nom']) ||  empty($_POST['prenom']) || empty($_POST['adresse']) || empty($_POST['npa'])|| empty($_POST['ville'])|| empty($_POST['email']) )
{
echo'<table align="center" width="1000">
<tr><td class="bodycentre"align="center" class="texte" valign="middle"  >';
echo'<br><br><br><br><br><br><samp class="texte" > ATTENTION seule le champ note peux rester vide!&nbsp;</span><a href="javascript:history.back();">Retour au formulaire </a>';
echo'
</td></tr>
<tr><td class="texte" colspan="2">
<hr class="texte">Site optimisé pour Safari.<br>
© 2011 Graphisme : Valentina Zofra et Sarah Richoux / Codage : Martial Croisier<br>
Contact : <a href="mailto:[email protected]" class="lien">Webmaster</a> / <a href="mailto:[email protected]" class="lien">Informations</a><br>
</td></tr></table>';
}
elseif($_SESSION['code'] != $_POST['verif'])  {
	echo'<table align="center" width="1000">
<tr><td class="bodycentre"align="center" class="texte" valign="middle"  >';
echo'<br><br><br><br><br><br><span class="texte"> ATTENTION le code sécurité est faux!</span> <a href="javascript:history.back();" class="bleu">Retour au formulaire </a>';
echo'
</td></tr>
<tr><td class="texte" colspan="2">
<hr class="texte">Site optimisé pour Safari.<br>
© 2011 Graphisme : Valentina Zofra et Sarah Richoux / Codage : Martial Croisier<br>
Contact : <a href="mailto:[email protected]" class="lien">Webmaster</a> / <a href="mailto:[email protected]" class="lien">Informations</a><br>
</td></tr></table>';
 }
else
{
//error_reporting(E_ALL);
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('phpmailer/class.phpmailer.php');
//include("phpmailer/examples/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$body             = ('Bonjour &nbsp;'.$_POST['nom'].'&nbsp;'.$_POST['prenom'].",<br><br>Vous venez de passer la commande suivante via le Shop des Kamikazes.<br><br>
 CD New Born :&nbsp;<strong>".$_POST['new']."</strong>&nbsp;fois<br><br>
 CD Show Must Go On :&nbsp;<strong>".$_POST['show']."</strong>&nbsp;fois<br><br>
 CD X :&nbsp;<strong>".$_POST['X'].
"</strong>&nbsp;fois<br><br>Prix total de la commande :&nbsp;<strong>".$_POST['prix'].
"Frs</strong><br><br><strong> Livraison et facturation:</strong><br><br>
 Nom &nbsp;Prénom:&nbsp;".$_POST['nom'].'&nbsp;'.$_POST['prenom']."<br><br>
Adresse :&nbsp;".$_POST['adresse']."<br><br>
NPA&nbsp;Ville:&nbsp;".$_POST['npa'].'&nbsp;'.$_POST['ville']."<br><br>
Email:&nbsp;".$_POST['email']."<br><br>
Note &nbsp;".$_POST['note']."<br>"
);
$body             = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.netplus.ch"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)                                     // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.netplus.ch"; // sets the SMTP server
$mail->Port       = 587;                    // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]"; // SMTP account username
$mail->Password   = "77srammars77";        // SMTP account password
$mail->SetFrom(''.$_POST['email'].'', ''.$_POST['nom'].''.$_POST['prenom'].'');
$mail->AddReplyTo(''.$_POST['email'].'',''.$_POST['nom'].''.$_POST['prenom'].'');
$mail->Subject    = "Voici une nouvelle commande depuis le shop des Kamikazes";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address);
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo'';
}

}
header("location:shopconfirme.php");

?>
Mais j'ai le message suivant qui s'affiche et toujours pas de redirection:
Deprecated: Function eregi_replace() is deprecated in /Applications/XAMPP/xamppfiles/htdocs/newskamikaze/kamikaze/shopmail.php on line 50
SMTP -> FROM SERVER:220 smtp1.netplus.ch ESMTP Postfix 
SMTP -> FROM SERVER: 250-smtp1.netplus.ch 250-PIPELINING 250-SIZE 20971520 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN 
SMTP -> FROM SERVER:250 2.1.0 Ok 
SMTP -> FROM SERVER:250 2.1.5 Ok 
SMTP -> FROM SERVER:354 End data with . 
SMTP -> FROM SERVER:250 2.0.0 Ok: queued as BCC5B21761C 

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/newskamikaze/kamikaze/shopmail.php:4) in /Applications/XAMPP/xamppfiles/htdocs/newskamikaze/kamikaze/shopmail.php on line 72
qu'est ce que je fait de faut ?

Re: problème de redirection

Posté : 04 janv. 2012, 18:00
par mars77
Hello,

J'ai trouvé la solution en passant avec du javascript..
<?
echo '<script language="Javascript">
<!--
document.location.replace("shopconfirme.php");
// -->
</script>';
?>
Merci quand même pour votre aide.

Re: problème de redirection

Posté : 04 janv. 2012, 20:12
par xTG
C'est pas très joli...
Pourquoi ne pas régler les erreurs qu'il t'annonce plutôt ?

Le eregi est à remplacer par un preg_replace.
Après le session_start() tu fermes les balises PHP pour les rouvrir juste après. D'une part ça sert à rien et d'autre part tu as surement un caractère invisible entre les deux qui occasionne l'erreur de header.