我是非编码人员或非常新人。我修改了现有的HTML表单以在电子邮件模板中工作。有一个字段(用户电子邮件地址)和提交按钮。当用户点击提交时,php脚本会向我发送一封包含提交数据的电子邮件。这件事适用于Gmail&桌面上的Outlook,但是当我打开电子邮件并单击移动应用程序上的提交按钮(例如,通过gmail,outlook或spark收件箱)时,它不起作用。我得到的错误(在被重定向到移动浏览器之后)是:"您需要提交表单"和验证错误(即没有输入数据)。虽然我收到一封电子邮件说提交表单,但没有收到任何数据(即使我确实输入了数据)。请帮忙!
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$email = $_POST['email'];
//Validate first
if(empty($email))
{
echo "we need your email address for this to work!";
exit;
}
if(IsInjected($email))
{
echo "Bad email value!";
exit;
}
$email_from = 'hello@melltoo.me';//<== update the email address
$email_subject = "New Pay&Ship Beta User from Existing Users";
$email_body = "The user $email.\n is responding positively to your email".
"He/she wants to be a part of beta testing for Pay&Ship ".
$to = "hello@melltoo.me";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP form to email sample form</title>
<!-- define some style elements-->
<style>
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
/*FORM STYLES*/
.tagline-form-object{margin-top:20px;text-align:center}.footer-form-input,
.tagline-form-input{background-color:#FFF;font-size:20px;padding:10px 15px;font-weight:700;color:#555459;border-radius:4px;width:300px;margin-right:10px}
.tagline-form-submit{appearance:none;-webkit-appearance:none;-moz-appearance:none;background-color:#0cb37b;font-size:20px;padding:10px 30px;border-radius:4px;font-weight:700;color:#FFF;text-shadow:0 1px 2px rgba(0,0,0,.5);cursor:pointer}
.tagline-form-submit:hover{background-color:#3DA7F2}
.tagline-form-submit:active{border-bottom:1px solid #194BA3;margin-top:1px}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>
<!-- Start code for the form-->
<form method="post" name="myemailform" action="form-to-email.php">
<p>
<input type="text" class="tagline-form-input" name="email" value="user-email@email.com">
</p>
<input class="tagline-form-submit" type="submit" name='submit' value="Add 25 AED to my account!">
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
</body>
</html>
答案 0 :(得分:0)
HTML电子邮件中的表单长期以来一直是冒险的风险,至今仍在继续。它存在一些安全风险,即某些电子邮件客户端会阻止与它的交互(例如Outlook),而大多数其他电子邮件客户端会对它们进行某种警告或有限的功能过滤。 (Campaign Monitor)
还有一种猜测(但没有真正可靠的事实)HTML表单可以降低某些ISP的可传递性。
建议将收件人发送到目标网页,以便通过其网络浏览器填写并提交表单,从而大大降低安全风险,以及电子邮件服务器可能出现的限制和奇怪行为。
另外 - 如果您向他们发送电子邮件,当您显然已经拥有电子邮件地址时,为什么要提交表格来收集电子邮件地址。而不是表单提交,在登录页面上执行POST或GET,并在URL的参数中使用电子邮件地址来处理您的需求。它将删除点击之外的所有用户互动。
答案 1 :(得分:0)
if (!isset($_POST['submit']))
的作用基本上是检查按钮是否被点击。在移动浏览器上;我怀疑人们会把他们的数据输入到现场;然后使用键盘上的开始按钮提交。
这意味着表单将被发布,但不能通过按下按钮。如果用if ($_SERVER['REQUEST_METHOD'] != 'POST')
替换第一行,这至少应该修复第一个错误。
对于第二个错误,您能否在提交表单后显示var_dump($_POST);
输出?