簡體   English   中英

HTML文件調用了運行良好的PHP,但在要打開的HTML上標記了PHP文件名

[英]HTML file calls PHP which runs fine but tags the PHP file name on the HTML I want to open

我是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 = "subscribe@myithost.net";
    $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._%-]+@[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

任何幫助將非常感激

您需要重定向用戶。 在您的php文件末尾放置類似這樣的內容

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

為PHP嘗試一下:

<?php
if(isset($_POST['email'])) {
    $email_to = "subscribe@myithost.net";
    $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._%-]+@[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



}
?>

更換:

    @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");
}
?>

注意:確保在header()函數調用之前未顯示任何字符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM