我有一个需要姓名,电话和和可选注释部分的注册表单。运行多个测试后,表单似乎提交并且(php代码的底部)页面将我重定向到“谢谢你的页面”。但我没有收到任何电子邮件。任何人都知道我在做什么错了?我的HTML表单提交但我没有收到电子邮件
<form class="register-form" name="registerform" method="post" action="form-to-email.php">
<div class="form-column">
<p>Fields marked with * are required.</p>
<label for="first_name">First Name *</label>
<input type="text" id="first_name" name="first_name" placeholder="John">
<label for="last_name">Last Name *</label>
<input type="text" id="last_name" name="last_name" placeholder="Smith">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" placeholder="503 999 9999">
<label for="comments">Comments</label>
<textarea id="comments" name="comments"></textarea>
</div><!--/ Form Column -->
<div class="submit-wrap"><input class="submit-form" type="submit" value="Register" /></div>
</form><!--/ Form -->
的PHP是这样的:?
<?php
$myemail = '[email protected]';
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$visitor_phone = $_POST['phone'];
$comments = $_POST['comments'];
$to = $myemail;
$email_subject = "$first_name\n $last_name\n registered for Winter Camp 2015";
$email_body = "They said: \n $comments". "Their phone number is $visitor_phone.\n".
$headers = "From: $myemail\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: registered-thanks.html');
>
您的服务器是如何设置的?您的服务器上是否安装了所需的位(即MTA等)并能够中继邮件? – slugonamission 2014-12-18 23:05:22
你的代码有错误。 '$ email_body ='不以分号结尾。 – RST 2014-12-18 23:10:32