0

我有 sendForm.php 文件,这是使用 PHPMailer 发送表单的 php。在标签之间有回声,我需要在标签之间使用 PHP 变量。这有可能吗?我知道将 PHP 和 JS 结合起来太过分了,但是我能做什么...我需要一个弹出窗口,这就是我也使用 JS 的原因。回声本身仅打印到网页本身。

$totalSize = ($totalSize/(1024*1024));
$totalSize = round($totalSize,2);

if(!$mail->Send()) {
   echo "Error sending form! You are trying to send too large files. Their size is: ", $totalSize, " MB";
   echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: ??? ");</script>';
   }

如何在 JS 中打印 $totalSize 变量来代替第二个回显中的那些问号?谢谢你的帮助。我还是个初学者。

4

3 回答 3

1

PHP 是一种服务器端语言,而 JavaScript 是一种客户端语言。如果您尝试在服务器端验证表单而不重新加载页面(并让 JavaScript 弹出警告),请查看AJAX

于 2013-06-03T09:19:53.577 回答
1
if(!$mail->Send()) {
   echo "Error sending form! You are trying to send too large files. Their size is: ". $totalSize. " MB";
   echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: '. $totalSize. '");</script>';
   }

//我更正了第一个回显中的一些错误(用点替换逗号)

于 2013-06-03T09:12:56.170 回答
0

尝试这个

  if(!$mail->Send()) {
    echo "Error sending form! You are trying to send too large files. Their size is: ".$totalSize." MB";
        ?>
<script type="text/javascript">
alert("Error sending form! You are trying to send too large files. Their size is: <?php echo $totalSize;?> ");
</script>
<?php } 
于 2013-06-03T09:13:02.557 回答