【发布时间】:2015-04-02 17:01:11
【问题描述】:
我的网站上有一个联系表格,使用当前代码向发件人和收件人发送电子邮件,一切正常。但是,一旦完成表单,页面就会打开 email.php,而不是显示我希望的弹出窗口。我不知道如何解决,因为我不习惯为 php 和 JS 编写代码。下面是我的代码。
<form method="post" action="email.php" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_self" novalidate>
<input type="text" value="" name="full_name" class="fullname" id="mce-name" placeholder="full name" required>
<input type="text" value="" name="phone_num" class="phonenum" id="mce-phone" placeholder="phone number" required>
<br>
<input type="email" value="" name="email" class="email" id="mce-EMAIL" placeholder="email address" required>
<div style="position: absolute; left: -5000px;"><input type="text" name="b_cdb7b577e41181934ed6a6a44_e65110b38d" value=""></div>
<div class="clear"><input type="submit" value="Submit" name="submit" id="mc-embedded-subscribe" class="button"></div>
</form>
<?php
if(isset($_POST['submit'])){
$to = "email@help.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$full_name = $_POST['full_name'];
$phone_num = $_POST['phone_num'];
$subject = "Title";
$subject2 = "Copy of your form submission";
$message = "Message";
$message2 = "Message2";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
if ($_POST['submit']) {
if ($name != '' && $email != '' && $subject != '' && $message != '') {
}
} else {
echo '<script>function displayPopup()
{
alert("Form submitted!");
}<script>';
}
}
?>
【问题讨论】:
-
如果你只是想显示一个警报,为什么要定义一个函数
displayPopup()? -
我不懂 PHP、JS。我一直在使用我发现的其他人的答案来尝试解决我遇到的问题。
标签: javascript php html css forms