2014-11-25 4 views
0

나는 PHP에별로 좋지 않지만 내 html에 연락처 양식을 추가하려고합니다. 나는 이것을 온라인에서 찾았지만 제대로 작동하는 것처럼 보였습니다. 그러나 양식이 다른 html 페이지에 제출되면 리디렉션하고 싶습니다.URL로 리디렉션되는 HTML 양식

당신은

<?php 
if(isset($_POST['email'])) { 

    // CHANGE THE TWO LINES BELOW 
    $email_to = "[email protected]"; 

    $email_subject = "Testing"; 


    function died($error) { 
     // your error code can go here 
     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 
     echo "These errors appear below.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['telephone']) || 
     !isset($_POST['comments'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 
    $comments = $_POST['comments']; // required 

    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
    } 
    if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
    } 
    if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />'; 
    } 
    if(strlen($error_message) > 0) { 
    died($error_message); 
    } 
    $email_message = "Form details below.\n\n"; 

    function clean_string($string) { 
     $bad = array("content-type","bcc:","to:","cc:","href"); 
     return str_replace($bad,"",$string); 
    } 

    $email_message .= "First Name: ".clean_string($first_name)."\n"; 
    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 
    $email_message .= "Comments: ".clean_string($comments)."\n"; 


// create email headers 
$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
@mail($email_to, $email_subject, $email_message, $headers); 
?> 

<!-- place your own success html below --> 

Thank you for contacting us. We will be in touch with you very soon. 

<?php 
} 
die(); 
?> 

답변

0

마지막 die();를 제거하고 또한

header('Location: http://www.yoursite.com/yourpage'); 

제거를 추가 할 수 있습니다하십시오) (

<!-- place your own success html below --> 
Thank you for contacting us. We will be in touch with you very soon. 
+0

도움을 주셔서 감사합니다 –

0

먼저 지난 다이를 제거; 코드에서

HTML 코드가 헤더 ("위치 : xyz.com/") 위/이전 온다 재

에 대한

다음 헤더 ('위치 : xyz.com/ ") 재 그래서 HTML 코드 전에 헤더 (위치)을 작성합니다. 작동하지.

당신이 다음 같이 location.href를 사용하는 HTML 코드 후 다른 페이지로 재 지정하려면 자바 스크립트 방법.

0

파일 맨 위에 ob_start();을 추가하십시오. 이렇게하면 출력 버퍼링이 설정되므로 출력이 에코되면 나중에 헤더를 설정할 수 있습니다.

는 리디렉션

header('location: location-to-file.php'); 

스크립트 실행이 완료된 후이 리디렉션 추가합니다.

+0

변경 사항을 실행할 때 다음과 같이 나타납니다 : 경고 : 헤더 정보를 수정할 수 없습니다 - 이미 보낸 헤더 (출력은 /home/content/16/10154316/html/testing/html_form_send.php에서 시작되었습니다 : 11) in /home/content/16/10154316/html/testing/html_form_send.php on line 90 –

관련 문제