没有收到邮件

时间:2013-07-18 11:56:08

标签: php html

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

的index.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>

contact.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。但我没有收到邮件

任何人都可以帮助我吗?我哪里错了?

3 个答案:

答案 0 :(得分:2)

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

另请查看此post

答案 1 :(得分:1)

请检查您的托管服务,我确信您的代码完全正常,因为我实际测试了它并且它完美运行。 :)您可能希望自己在 http://goo.gl/sDIL6 上进行测试。 (我会在那里待几天..)

Fill out the form


Received message

答案 2 :(得分:0)

您的托管服务是否阻止端口25?我已经在我的服务器上对它进行了测试,它运行良好。

如果您使用的是000webhost,那么确实如此。这是最常见的免费服务,他们暂时取消了对邮件的支持。

相关问题