【问题标题】:Not receiving the mail收不到邮件
【发布时间】:2013-07-17 08:44:27
【问题描述】:

我想使用 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。但我没有收到邮件

谁能帮帮我?我哪里错了?

【问题讨论】:

  • 你检查过你的垃圾文件夹吗?
  • 签入Spam folder。您是否从contact.php 收到else part 警报
  • @RohanKumar:我只注意到 if 部分。我什至检查了垃圾邮件文件夹。我没有收到。
  • 看看mailq可能你的服务器没有配置
  • 我们的答案是否解决了您的问题?如果有,请采纳! :)

标签: php html


【解决方案1】:

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


【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      还可以查看post

      【讨论】:

        猜你喜欢
        • 2014-12-26
        • 2015-09-16
        • 2014-10-11
        • 2014-04-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多