php - 将联系表发布到 html 文档
问题描述
我目前有一个联系页面,当它被提交时会通过电子邮件发送给我。我想将这些字段发送到服务器上的另一个 htm 页面,以便员工可以通过在浏览器中查看页面来访问信息。因此,即使他们无法访问电子邮件,也可以通过浏览器查看该页面。
发送的信息必须在表单上累积,即新提交的信息必须提交到 ame 表单,而不删除以前的提交。
我要修改代码吗?我是否进行了一些更改,例如将 'mymail' 更改为 'myform = "form.htm" ' 我进行了一些更改并尝试提交,但不知道如何使表单工作。
下面是发送电子邮件的代码。
<?php
/* Set e-mail recipient */
$myemail = "mail@abc.co.za";
$subject = "Contact Form";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name']);
$contactnr = check_input($_POST['contactnr']);
$email = check_input($_POST['email']);
$phoneoremail = check_input($_POST['phoneoremail']);
$message = check_input($_POST['message']);
$ipaddress = $_SERVER['REMOTE_ADDR'];
$iphost = $_SERVER['HTTP_HOST'];
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Prepare the message for the e-mail */
$message = "Contact form has been submitted
Details:
Name: $name
Phone Number: $contactnr
E-mail: $email
Message: $message
Sender IP Address: $ipaddress
Form submitted via server: $iphost
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thankyou.htm');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please provide missing information so we can assist you:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
解决方案
如果您想将其发布到 HTML 页面并通过电子邮件发送,为什么不直接写入 HTML 文件?
$file = 'formdata.html';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "Details:<br>
Name: $name<br>
Phone Number: $contactnr<br>
E-mail: $email<br>
Message: $message<br>
Sender IP Address: $ipaddress<br>
Form submitted via server: $iphost<br><hr>";
// Write the contents to the file
file_put_contents($file, $current);
也许包括 formdata.html 然后作为 iFrame 在只有员工可以访问的页面上?
推荐阅读
- string - VBA中的字符串与字符串()
- google-cloud-platform - oAuth JWT 导致无效参数错误 (400)
- css - 如何在 CSS 网格中创建水平对齐的卡片?
- assert - C语言中的断言
- javascript - 如何从 nuxt 路由器模块的 router.js 文件访问 Vuex 商店?
- c++ - C ++如何仅对存储在向量中的偶数值求和?
- c - C动态包含库,通过将原始函数数据复制到内存块
- python - 导出到 .csv 或 .xslx 时如何翻译刮取文本的语言?
- python - Django:将多个数据传输到下一个模板
- python - 创建图例