我可以将 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";
}
?>