简单的PHP邮件表单无法在服务器上运行

时间:2016-03-01 04:02:19

标签: php html

我写了一个简单的PHP邮件表单,但它拒绝在一台服务器上运行,但在另一台服务器上运行。两台服务器都运行PHP 5.4,其他PHP程序在有问题的服务器上运行,但邮件不会发送。

我已经将邮件恢复到最简单的代码,但是为什么一台服务器不会发送邮件而感到难过。是否需要激活配置或我可以执行的测试来诊断问题?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Simple PHP Mailer</title>
    </head>

    <body>

        <form action="" method="post">
            First Name: <input type="text" name="first_name"><br>
            Last Name: <input type="text" name="last_name"><br>
            Email: <input type="text" name="sender_email"><br>
            Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
            <input type="submit" name="subdata" value="Submit">
        </form>

        <?php   
            //Taken from: http://stackoverflow.com/questions/18379238/send-email-with-php-from-html-form-on-submit-with-the-same-script

            if(isset($_POST['subdata'])){
                $to = 'myname@gmail.com'; // this is your Email address
                $from = $_POST['sender_email']; // this is the sender's Email address
                $fname = $_POST['first_name'];
                $lname = $_POST['last_name'];
                $subject = "PHP Email Form Test";
                $message = $fname . ' ' . $lname . ' (' . $from . ') wrote the following:' . '\n\n' . $_POST['message'];
                $headers = 'From: user@gmail.com' . "\r\n" .
                'Reply-To: user@gmail.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();

                if (mail($to, $subject, $message, $headers)) {
                    echo 'Mail Sent. Thank you ' . $fname . ', we will contact you shortly.';
                    }else{
                    echo 'Mail Error';
                }

            }
        ?>  
        </body>
</html>

非常感谢任何帮助。 千瓦

0 个答案:

没有答案