2013-04-14 1 views
0

이메일을 보낸 후 사용자를 리디렉션하고 싶습니다.
email() -method (예 : header() -method) 다음에 코드를 넣지 않으면 코드가 실행됩니다.
힌트가 있습니까?PHP 코드 내의 헤더 리디렉션이 작동하지 않습니다.

function process() 
{ 
    $msg = "Form Contents: \n\n"; 
    foreach($this->fields as $key => $field) 
     $msg .= "$key : $field \n"; 

    $to = '[email protected]'; 
    $subject = 'thesubject'; 
    $from = $this->fields['email']; 

    mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n"); 

    header('Location: thanks.html'); 
} 
+0

어떤 오류가 발생합니까? –

+0

D : \ xampp \ php \ logs \ php_error_log의 D : \ xampp \ htdocs \ process_form.php에서 예상치 못한 'header'(T_STRING), 예상 함수 (T_FUNCTION) 구문 오류, PHP 구문 분석 오류가 발생했습니다. – spamup

+0

전자 메일은 오류없이 전송됩니까? @mail (...)을 사용하면 어떨까요? – djot

답변

-1

after header ('location : ....'); 당신은 출구를 추가해야합니다; 그렇지 않으면 스크립트는 끝날 때까지 계속 실행됩니다.

header('Location: thanks.html'); 
exit; 
+0

나는 이것을 잘 시도했다 : 기회 없음. 아무것도 안 일어날거야. – spamup

+0

어쨌든 출구를 추가해야합니다.) – djot

+0

이것은 완전한 코딩입니다. [pastebin] (http://pastebin.com/UhTS1aKP) – spamup

0

위치는 상대가 아닌 절대적이어야합니다. 나는 비슷한 문제로 실행하면 케이스가 foreach 코드 블록에 의해 봉쇄해야하기 때문에 괄호 누락, 여기로

header("Location: /myPath/thanks.html"); 
+0

시도해보십시오. : :( – spamup

3

, 그것은 일반적으로 라인의 끝에 누락 된 세미콜론 나 {}. documentation을 참조하십시오.

0
<?php 
header("Location: http://www.example.com/"); /* Redirect browser */ 

/* Make sure that code below does not get executed when we redirect. */ 
exit; 
?> 

제 경우에는 인용 부호가 있습니다. 그랬어.

관련 문제