2012-10-04 59 views
0

我是新來的PHP的HTML的PHP​​文件名,HTML文件調用PHP它運行很好,但標籤上我想開

後續的HTML調用send_form_email.php

<form name="contactform" method="post" action="send_form_email.php"> 
<p align="center"><font face="Arial" color="#4F4F4F"><strong>Subscribe to our 
News letter:&nbsp; </strong></font><input type="text" value="enter your email address"   onfocus="blank(this)" onblur="unblank(this)" name="email" size="20">&nbsp;&nbsp;&nbsp; 
<input type="submit" value="Submit"> 

後續PHP代碼運行正常:

<?php 
if(isset($_POST['email'])) { 
    $email_to = "[email protected]"; 
    $email_subject = "News Letter Opt In"; 

    function died($error) { 
     echo "We are very sorry, but the email adress submitted does not appear to be valid"; 
     echo "The error appears below<br /><br />"; 
     echo 'Please go back and fix the error<br /><br />'; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['email'])) { 
     died('We are sorry, but there appears to be a problem with the email you submitted.'); 
    } 
    $email_from = $_POST['email']; // 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 />'; 
    } 

    if(strlen($error_message) > 0) { 
     died($error_message); 
    } 

    $email_message = "News Letter Opt in Member, see below.\n\n"; 

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

    $email_message .= "Email: ".clean_string($email_from)."\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); 
?> 
<?php include 'index.html'; ?> 
<?php 
} 
?> 

但我的問題是,它返回我http://www.myithost.net/send_form_email.php不www.myithost.net/index.html

任何幫助將不勝感激

回答

0

您需要重定向用戶。裝上去likethis在你的PHP文件的末尾

header("Location: http://mydomain.com/index.html"); 
0

嘗試本作的PHP:

<?php 
if(isset($_POST['email'])) { 
    $email_to = "[email protected]"; 
    $email_subject = "News Letter Opt In"; 

    function died($error) { 
     echo "We are very sorry, but the email adress submitted does not appear to be valid"; 
     echo "The error appears below<br /><br />"; 
     echo 'Please go back and fix the error<br /><br />'; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['email'])) { 
     died('We are sorry, but there appears to be a problem with the email you submitted.'); 
    } 
    $email_from = $_POST['email']; // 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 />'; 
    } 

    if(strlen($error_message) > 0) { 
     died($error_message); 
    } 

    $email_message = "News Letter Opt in Member, see below.\n\n"; 

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

    $email_message .= "Email: ".clean_string($email_from)."\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); 

    header("Location: http://www.example.com/index.html"); // <--- ADD ME 
    exit(); // <--- ADD ME 



} 
?> 
0

替換:

@mail($email_to, $email_subject, $email_message, $headers); 
    ?> 
    <?php include 'index.html'; ?> 
    <?php 
} 
?> 

通過:

@mail($email_to, $email_subject, $email_message, $headers); 
    header("Location: http://mydomain.com/index.html"); 
} 
?> 

NB:確保沒有字符顯示在標題之前()函數調用。

+0

您好,非常感謝您所做的更改,現在一切正常 – user1720251

相關問題