PHP联系表格似乎有效,没有收到电子邮件

时间:2016-03-27 00:29:54

标签: php forms contact

不是PHP专家。话虽如此,我之前使用过该系统,似乎有一天停止工作。即使我没有收到任何错误消息,我似乎也无法收到电子邮件。我不知道出了什么问题。

表单页面:

<form method="POST" name="contactform" action="contact-form-handler.php"> 

<label for='name'>Your Name:</label> <br>
<input type="text" name="name">

<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>



What does this concern?<br> 
<select name="options">
<option value="null">--</option>
<option value="IEP">IEP</option>
<option value="Section 504">Section 504</option>
<option value="Other">Other</option>
</select>


<p style="width: 50%">Please include in your message what type of service you are inquiring about. Please be as descriptive as possible so we can help you more efficiently. Thank you.</p>


<label for='message'>Message:</label> <br>
<textarea name="message" cols="45" rows="7"></textarea>

<input type="image" src="img/submit.png" alt="Submit"> <br>
</form>

处理:

<?php 
$errors = '';
$myemail = 'louie540x@gmail.com;';
if(empty($_POST['name'])  || 
   empty($_POST['email']) ||
   empty($_POST['options']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name'];
$email_address = $_POST['email']; 
$message = $_POST['message']; 
$options = $_POST['options']; 

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 Regarding a(n): $options \n \n Message: \n \n $message"; 

$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.php');
} 
?>

<?php include 'template/top.php'; ?>

<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>

<?php include 'template/bottom.php'; ?>

1 个答案:

答案 0 :(得分:1)

$myemail = 'louie540x@gmail.com;';

应该是:

$myemail = 'louie540x@gmail.com';

然而,这可能不是你唯一的问题......