2

我可以将 php 文件中的文本发送到 html 文件中的变量吗?我的 php 中有一个 if 语句,用于检查字段是否为空。如果它是空的,那么我想向我的 html 文件发送一个文本说“请填写该字段”并将其放在我的 html 中的标签中。有办法吗?

<?php 

$name = $_REQUEST['author'];
$from = $_REQUEST['email'];
$subj = $_REQUEST['sub'];
$message = $_REQUEST['msg'];
$subject = $subj;
$body = $message;
$headers .= "From: ".$from;

$to = "mail@mail.com";

if ($name = ''){
     HERE i want to send a text to a variable named 'reason' in my html in case $name is empty.
    }

if(mail($to,$subject,$body,$headers)) {
    header( "Location: http://www.mysite.com/contactForm-english" );
    } else {
echo "There was a problem sending the mail. Check your code and make sure that the e-mail address ".$to." is valid";
}

?>
4

2 回答 2

0

是的,您只需像任何其他普通回显一样回显 HTML。

echo '<label>Test</label>';

它可以像这样嵌入到您的 HTML 中(显然,只要它是一个 PHP 文件):

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>

    <body>
        <?php echo $something === true ? '<label>test</label>' : ''; ?>
    </body>
</html>
于 2012-12-28T07:53:53.477 回答
0
<?php echo $variable; ?>
于 2012-12-28T07:55:20.907 回答