2014-09-13 2 views
-2

어떤 이유로이 PHP 문이 지정된 페이지로 리디렉션되지 않습니다. 그것은 여기 나에게이 오류출력 후 PHP 리디렉션

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/srimeru/emailpage.php:203) in /Applications/XAMPP/xamppfiles/htdocs/srimeru/emailpage.php on line 229 

를 제공이 섹션 내 코드입니다 :

<?php 
if(!isset($_POST["submit"])){ 
    ?> 
    <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>"> 
     <p>From: <input type="text" name="from"></p><br> 
     <p>Subject: <input type="text" name="subject"></p><br> 
     <p>Message: <br><textarea rows="10" cols="40" name="message"></textarea></p><br> 
     <input type ="submit" name="submit" value="Email"> 
    </form> 
    <?php 
} else { 
    $from = test_input($_POST["from"]); 
    $subject = test_input($_POST["subject"]); 
    $message = test_input($_POST["message"]); 

    $con = mysqli_connect("localhost", "root", "chendu", "SriMeru"); 
     if (mysqli_connect_errno()){ 
      echo "Failed to connect to Server"; 
     } 
    $sql = "SELECT email FROM users"; 
    $result = mysqli_query($con, $sql); 
while ($row = mysqli_fetch_array($result)){ 
     mail($row['email'], $subject, $message,"From: $from\n"); 
     echo $row['email'] . $subject . $message . $from . "<br>"; 
    } 
    echo"Successful Email"; 
    header('location: http://localhost/srimeru/emailpage.php'); 
    exit(); 
} 


function test_input($data){ 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
    } 
?> 
+0

중복 질문이있는 곳 –

+0

기본적으로 경고는 이전에 아무 것도 출력하지 않았다면 머리말을 수정할 수 없다는 경고입니다. 'header()'를 호출하기 전에 html이나 echo를 사용할 수 없습니다. 두 번째 단락 http://php.net/manual/en/function.header.php와 첫 번째 예를 확인하십시오. –

+0

출력 후에도 다른 페이지로 리디렉션 할 수있는 다른 방법이 있는지 알고 있습니까? –

답변

0

당신은 작업 위치 헤더를 얻기 위해 echo"Successful Email"; 문을 제거해야합니다.

+0

이게 작동하지 않는 것 같습니다. –

+0

'emailpage.php on line 229'은 무엇입니까? 아웃 아웃을 시작하는 무언가가 있어야합니다. – nilobarp

+0

머리글 앞에 ** 아무 것도 ** 삽입 할 수 없습니다. 'echo $ row [ 'email']을 제거해보십시오. $ 제목. $ 메시지. $에서. "
"; '도 마찬가지입니다. – andrew