0

我想使用PHP 邮件功能创建一个联系表。我正在通过在免费的网络托管服务提供商上开发来学习这个过程。这是我的文件:

索引.html

<!DOCTYPE html>
<html>  
    <head>
        <meta charset="utf-8">
        <title>HTML5 Contact Form</title>
        <link rel="stylesheet" media="screen" href="styles.css">
    </head>     
    <body>
        <div id="contact">
            <form class="contact_form" action="contact.php" method="post" name="contact_form">
                <ul>
                    <li>
                         <h2>Contact Us</h2>
                         <span class="required_notification">* Denotes Required Field</span>

                    </li>
                    <li>
                        <label for="name">Name:</label>
                        <input type="text" id="name" name="name" placeholder="John Doe" required />
                    </li>
                    <li>
                        <label for="email">Email:</label>
                        <input type="email" name="email" id="email" placeholder="john_doe@example.com" required /> <span class="form_hint">Proper format "name@something.com"</span>

                    </li>
                    <li>
                        <label for="message">Message:</label>
                        <textarea name="message" id="message" cols="40" rows="6" required></textarea>
                    </li>
                    <li>
                        <button class="submit" id="submit_btn" type="submit">Submit Form</button>
                    </li>
                </ul>
            </form>
        </div>
    </body>
</html>

联系人.php

<?php
    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    $field_message = $_POST['message'];
    $mail_to = 'babloopuneeth@gmail.com';
    $subject = 'Message from a site visitor '.$field_name;
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) {
        ?>
        <script language="javascript" type="text/javascript">
            alert('Thank you for the message. We will contact you shortly.');
            window.location = 'sample.html';
        </script>
    <?php
     } else { ?>
        <script language="javascript" type="text/javascript">
            alert('Message failed. Please, send an email to gordon@template-help.com');
            window.location = 'sample.html';
        </script>
    <?php
     } 
?>

我也有一个styles.css文件。我收到警报框说Thank you for the message。但我没有收到邮件

谁能帮我?我哪里错了?

4

3 回答 3

2

您使用的免费托管服务可能不允许此功能(我认为它不会)您检查了吗?

另请查看这篇文章

于 2013-07-18T12:12:27.063 回答
1

请检查您的托管服务,我确信您的代码都很好,因为我实际测试过它并且运行良好。:) 您可能想自己在http://goo.gl/sDIL6上进行测试。(我会把它放在那里几天..)

填写表格


收到消息

于 2013-07-18T12:50:59.873 回答
0

您的托管服务是否阻塞了 25 端口?我已经在我的服务器上对其进行了测试,并且效果很好。

如果您使用的是000webhost,则可以。这是最常见的免费服务,不久前他们取消了对邮件的支持。

于 2013-07-18T21:28:57.217 回答