我的网站上有一个联系我们页面。我想要的是当有人填写表格并点击发送按钮时。消息应该到达我的 gmail。我为它编写了以下代码。它不工作。有没有其他方法我可以做到这一点。
html代码:
<form id="ContactForm" action="contacts.php" method="post">
<div>
<div class="wrapper"> <strong>Name:</strong>
<div class="bg">
<input type="text" class="input" name="name">
</div>
</div>
<div class="wrapper"> <strong>Email:</strong>
<div class="bg">
<input type="text" class="input" name="email">
</div>
</div>
<div class="textarea_box"> <strong>Message:</strong>
<div class="bg">
<textarea cols="1" rows="1" name="message"></textarea>
</div>
</div>
<a href="javascript:;" onclick="document.getElementById('ContactForm').submit();" class="button"><span>Send</span></a> <a href="#" class="button"><span>Clear</span></a> </div>
</form>
php代码
<?php
session_start();
$to = "someemail@gmail.com";
$subject = "Someone Tried to contact you";
$message = $_POST['message'];
$fromemail = $_POST['email'];
$fromname = $_POST['name'];
$lt= '<';
$gt= '>';
$sp= ' ';
$from= 'From:';
$headers = $from.$fromname.$sp.$lt.$fromemail.$gt;
mail($to,$subject,$message,$headers);
echo "mail sent";
exit();
?>