我无法让我的 javascript 超链接按钮将数据发布到我的 php 表单电子邮件脚本。我尝试过几种不同的方法,但似乎没有任何效果。任何帮助表示赞赏。谢谢你。
我的表单代码:
<form id="form" action="contactform.php" method="POST" enctype="text/plain" >
<fieldset>
<label><strong>Your Name:</strong><input id="name" type="text" name="name"> </label>
<label><strong>Your Phone Number:</strong><input id="phone" type="text" name="phone"></label>
<label><strong>Your E-mail:</strong><input id="email" type="text" name="email"></label>
<label><strong>Your Message:</strong><textarea id="message" name="message"></textarea></label>
<div class="btns"><a href="contacts.html" class="button">Clear</a><a href="#" onclick="document.getElementById('form').submit();" class="button">Send</a></div>
</fieldset>
</form>
联系表格.php:
<?php
var_dump($_POST);
if (isset($_POST['form'])) {
$name = $_POST['name'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'emailaddress@gmail.com';
$email_subject = "Contact Form Submission";
$email_body = "Name: $name\n" . "Phone: $phone\n" . "Messge: $message";
$to= 'emailaddress@gmail.com';
$headers= "From: $email_from \r\n";
$headers.= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
echo "Thank you for your interest. I will contact you shortly.";
}else{
echo "It didn't work.";
}
?>
另外,我在 php 的开头有 var_dump 仅用于调试目的。不会成为最终代码的一部分。