我的PHP联系表单中出现500内部服务器错误

时间:2013-03-03 01:35:36

标签: php smtp internal-server-error server-error

我在这里有一个PHP联系表格: leongaban.com

下面是我点击提交后我收到的500(内部服务器错误)的屏幕截图

enter image description here

HTML表单

<div class="the-form">
            <form id="contact">
                <div id="status"></div>
                <div>
                    <label for="name">Your Name</label>
                    <input type="text" name="name" id="name" value="" tabindex="1">
                </div>

                <div>
                    <label for="email">Your Email</label>
                    <input type="text" name="email" id="email" value="" tabindex="2">
                </div>

                <div>
                    <label for="textarea">Message:</label>
                    <textarea cols="40" rows="8" name="comments" id="comments" tabindex="3"></textarea>
                </div>

                <div>
                    <input class="submit-button" id="submit" type="submit" value="Submit" tabindex="5">
                </div>
            </form><!-- #contact -->
        </div><!-- .the-form -->

我的Javascript

$(function(){

$('#submit').click(function(){

    var form_data = {
        name: $('#name').val(),
        email: $('#email').val(),
        comments: $('#comments').val()
    };

    $.ajax({
        url: "includes/send.php",
        type: 'POST',
        data: form_data,
        success: function(status) {
            if (status == 'success') {
                $('#status').html('<h3 class="success">Thank You!</h3>')
                            .hide().fadeIn(2000);
            } else {
                $('#status').html('<p class="error">Both name and email are required fields.</p>')
                            .hide().fadeIn(2000);
            }
        } // end send contact form
    });  //end ajax

    return false;
    });  //end send contact form click
});

我的PHP

<?php

$name = $_POST['name'];
$email = trim($_POST['email']);
$comments = $_POST['comments'];
$error = array();

$site_owners_email = 'myEmail@gmail.com'; // Replace this with your own email address
$site_owners_name = 'Leon Gaban'; // replace with your name

if (strlen($name) < 2) {
    $error['name'] = "Please enter your name.";    
}

if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email))     {
    $error['email'] = "Please enter a valid email address.";    
}

if (!$error) {
$response = 'success';
$subject  = $name . ' needs help from CodePopper!';
$body     = 'Codepopper,' . "\n\nName: " . $name . 
            "\nEmail: " . $email . 
            "\nComments: " . $comments;

require_once 'lib/swift_required.php';

$transport = Swift_SmtpTransport::newInstance('hostname', 25)
            ->setUsername('username')
            ->setPassword('password')
;

$mailer = Swift_Mailer::newInstance($transport);    

$message = Swift_Message::newInstance();
$message->setSubject($subject);
$message->setFrom(array('myEmail@gmail.com' => 'leongaban.com'));
$message->setTo(array('myEmail@gmail.com' => 'Leon Gaban'));
$message->setBody($body);

$result = $mailer->send($message);

echo $response;


} # end if no error
else {
$response = 'error';

    echo $response;
} # end if there was an error sending

1 个答案:

答案 0 :(得分:0)

我忘了在我的电子邮件主机设置中输入我的send.php文件

$transport = Swift_SmtpTransport::newInstance('leongaban.com', 25)
            ->setUsername('my email')
            ->setPassword('my password');

旁注,我现在可以访问我的服务器了:)