我有一个HTML页面,在phonegap中转换,它有一个contact. HTML在contact form中,我有姓名,邮件id和评论。我想要所有的三个字段被邮寄到我的邮箱id。如何做到这一点。
我的Php页面是在一些免费的网站托管,如http://www.kishorebt.net84.net/contact-form-handler.php所以每当我点击发送我得到的Php代码在我的浏览器。
我的页面没有在服务器上运行所以如何实现这一点。
我的html页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
</head>
</head>
<body>
<h1>Contact us</h1>
<form method="POST" name="contactform" action="http://www.kishorebt.net84.net/contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
<script language="JavaScript">
var frmvalidator = new Validator("contactform");
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>
和我的php页面
<?php
$errors = '';
$myemail = 'kishorebt11@gmail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:n Name: $name n Email: $email_address n Message n $message";
$headers = "From: $myemailn";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
这是一个将CGI转化为应用程序的好例子。首先将HTML4转换为HTML5。您可以使用我的通用样板开始。有三(3)个大的不同值得注意。
html5的新开始元素是:
<!DOCTYPE html>
第二个最重要的元素是
<meta name="viewport" content="width=device-width">
第三个是听者。许多初学者在这部分旅行。添加这个侦听器非常重要。它允许phonegap库在您调用任何库之前准备好电话上的所有设备。
// Wait for PhoneGap to load
document.addEventListener("deviceready", onDeviceReady, false);
//
function onDeviceReady() {
然而,如果你不打算使用这些设备,你至少应该有一个<body onload=loaded()>