无法使用电子邮件的mailto功能发送表单数据

时间:2014-08-24 08:43:24

标签: html forms

我有一个表单,我想使用HTML的mailto函数电子邮件将其数据发送到我的电子邮件ID。但这不适合我。请建议我使用HTML执行此操作的最佳方法。

以下是我的代码。

<html>
<head>
<title>
Contact us
</title>
<style>
h1
{
margin-top:30px;
text-align:center;
}
td
{
font-weight:bold;
}
</style>
</head>
<body bgcolor="#cococo">
<h1>
Call us at
<p>
995-3100-995
</h1>
<div style="text-align:center;"><img src="phone.jpg"/></div>
<p><p><p><p>
<h1>Let us contact you..</h1>
<form action"mailto:luthra.vaibhav@gmail.com" method="post" enctype="text/plain">
<fieldset>
<legend style="text-align:center;"><h2>Your contact details</h2></legend>
<table style="margin-left:40%">
<tr>
<td>Name</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text"></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="submit" value="Contact Me" align="right"></td>
<td><input type="reset" value="Clear All"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

尝试使用PHP。 MAILTO标记只是一个链接。

文件index.html:

<html>
<head>
<title>
Contact us
</title>
<style>
h1
{
margin-top:30px;
text-align:center;
}
td
{
font-weight:bold;
}
</style>
</head>
<body bgcolor="#cococo">
<h1>
Call us at
<p>
995-3100-995
</h1>
<div style="text-align:center;"><img src="phone.jpg"/></div>
<p><p><p><p>
<h1>Let us contact you..</h1>
<form action="email.php" method="post" enctype="text/plain">
<fieldset>
<legend style="text-align:center;"><h2>Your contact details</h2></legend>
<table style="margin-left:40%">
<tr>
<td>Name</td>
<td><input type="text" name="data"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact"></td>
</tr>
<tr>
<td><input type="submit" value="Contact Me" align="right"></td>
<td><input type="reset" value="Clear All"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

文件email.php:

function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}

if($_POST) {
$emailTo = 'email@gmail.com';
$data = addslashes(trim($_POST['email']));
if(!$data) {
$array = array();
$array['valid'] = 0;
$array['message'] = 'Insert a valid data!';
echo json_encode($array);
}
else {
$subject = 'Header';
$body = "BODY";
// uncomment this to set the From and Reply-To emails, then pass the $headers variable to the "mail" function below
// $headers = "From: ".$user_token." <" . $user_token . ">" . "\r\n" . "Reply-To: " . $user_token;
mail($emailTo, $subject, $body);
}

}

答案 1 :(得分:0)

你错过了等号

<form action="mailto:luthra.vaibhav@gmail.com" 
      method="post" enctype="text/plain">