尝试使用联系表单处理请求时遇到500内部服务器错误错误

时间:2017-11-14 09:04:30

标签: php html contact-form

我已经使用这个php编码获取了我最近用于我们客户联系页面的联系表单,当我测试页面时,单击提交按钮会出现此错误: 尝试使用以下页面处理请求时遇到500内部服务器错误。

http://shajjanlaw.com/contact.html

HTML

<form name="contactform" action="contact-form-handler.php" method="post">
  <div class="cnt_field cnt_field1">
    <label for='name'>First Name:</label>
    <input name="name" type="text" class="cnt_input">
</div>
<div class="cnt_field cnt_field1 cnt_field_ml">
    <label>Last Name:</label>
    <input name="lastname" type="text" class="cnt_input" >
</div>
<div class="cnt_field">
    <label for='email'>Email Address:</label> 
    <input name="email" type="text" class="cnt_input">
</div>
<div class="cnt_field">
    <label for='message'>Message:</label>
    <textarea name="message" cols="" rows="" class="cnt_msg"></textarea>
</div>
<input name="submit" type="submit" class="send_btn" value="Send">
</form>

PHP

<?php 
    $errors = '';
    $myemail = 'shajjan@shajjanlaw.com';//<-----Put Your email address here.
    if(empty($_POST['name'])  || 
     empty($_POST['email']) || 
     empty($_POST['message']))
    {
        $errors .= "\n Error: all fields are required";
    }

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

    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 | Shajjan & Associates";
        $email_body = " A new message has been recieved from your website's contact page.\n".
        "\n From: $email_address \n Name: $name \n Last Name: $lastname \n \n Message: \n $message"; 

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

        mail($to,$email_subject,$email_body,$headers);
        //redirect to the 'thank you' page
        header('Location: contact-form-thank-you.html');
    } 
    ?>
    <!DOCTYPE HTML> 
    <html>
    <head>
        <title>Contact form handler</title>
    </head>

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


    </body>
    </html>

0 个答案:

没有答案