php邮件功能发送电子邮件,但收件人没有收到邮件

时间:2018-01-27 10:13:09

标签: php html server

所以我是一名前端初学者,我遇到了这个问题。我搜索了高低不同的东西,我的灵魂不足。 Plx halp。

所以情况就是这样:

  1. 页面是实时的,已经配置了邮件帐户(我猜),因为它可以重新发送和发送邮件。
  2. 服务器确实支持php5 / php7
  3. 单击“提交”按钮会返回正在发送的邮件的真实值
  4. PHP代码似乎没有错误
  5. 邮件程序功能与操作
  6. 中提到的路径一起保存在不同的文件中

    尽管如此,当点击提交时,成功的消息和邮件永远不会传递给收件人

    笏???

    PHP代码:

    <?php
    
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // Get the form fields, removes html tags and whitespace.
        $name = strip_tags(trim($_POST["name"]));
        $name = str_replace(array("\r","\n"),array(" "," "),$name);
        $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
        $message = trim($_POST["message"]);
    
    // Check the data.
    if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        header("Location: http://www.xxx.pl/index.php?success=-1#contact");
        exit;
    }
    
    $recipient = "yyy@xxx.pl";
    
    // Set the email subject.
    $subject = "New contact from $name";
    
    // Build the email content.
    $email_content = "Name: $name\n";
    $email_content .= "Email: $email\n\n";
    $email_content .= "Message:\n$message\n";
    
    // Build the email headers.
    $email_headers = "From: $name <$email>";
    
    // Send the email.
    mail($recipient, $subject, $email_content, $email_headers);
    
    // Redirect to the index.html page with success code
    header("Location: http://www.xxx.pl/index.php?success=1#contact");
    
    
    } else {
        echo "There was a problem with your submission, please try again.";
      }
    ?>
    

    HTML表格:

    <footer class="footer" id="contact">
                <a href="https://github.com/xxx" target="_blank" class="footer__git--link"><i class="icon-github footer__git--icon"></i></a>
            </div>
            <form method="post" action="vendor/php/mailer.php" class="contact">
                <label for="name">What's Your name?</label>
                <input type="text" name="name" id="name" pattern="[a-zA-Z]*" required>
                <label for="email">Toss Your email here &rarr;</label>
                <input type="email" name="email" id="email" required>
                <label for="message">Do tell!</label>
                <textarea name="message" id="message" cols="30" rows="10" placeholder="For instance: &quot;I'm tottaly enjoying your page!" required></textarea>
                <input type="submit" value="Shoot it! &rarr;" class="contact__btn btn">
                <?php
                    if($_GET['success'] == 1) {
                        echo "<div class=\"contact__message succes\">Got it!</div>";
                    }
                ?>
            </form>
    

0 个答案:

没有答案