【问题标题】:Can't send email with PHP [duplicate]无法使用 PHP 发送电子邮件 [重复]
【发布时间】:2014-08-16 01:44:59
【问题描述】:

我正在学习 PHP,我发现了一段可以使用 PHP 发送电子邮件的代码。但是这封电子邮件从未出现在我的收件箱中。我已经测试了许多电子邮件并检查了每个垃圾邮件箱。

这是我的代码:

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = strip_tags(trim($_POST["nome"]));
    $name = str_replace(array("\r","\n"),array(" "," "),$name);
    $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
    $assunto = trim($_POST["assunto"]);
    $message = trim($_POST["mensagem"]);

    if ( empty($name) OR empty($message) OR empty($assunto) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // Set a 400 (bad request) response code and exit.
        http_response_code(400);
        include("contact.php");
        ?>
        <script type="text/javascript">
            $(document).ready(function () {
                alert("Oops! There was a problem with your submission. Please complete the form and try again.");
            })
        </script>
        <?
        exit;
    }

    $recipient = "contact@email.com";

    $email_content = "Name: $name\n";
    $email_content .= "Email: $email\n\n";
    $email_content .= "Message:\n$message\n";

    $email_headers = "From: $name <$email>";

    if (mail($recipient, $assunto, $email_content, $email_headers)) {
        http_response_code(200);
        include("contact.php");
        ?>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#resultado").html("SUCCESS!");

                setTimeout(function(){ $("#resultado").fadeOut() }, 5000);

            })
        </script>

它在发送电子邮件时执行200 代码。

【问题讨论】:

  • 您是从网络服务器还是您自己的计算机上运行它?
  • 自己的电脑,但使用 MAMP。
  • 这可能是问题所在,您的邮件在到达接收服务器上的垃圾邮件过滤器之前就已被删除,因为它是从一个非常不可靠的地址发送的。它可能已经被您的 ISP 阻止了。
  • 您的 ISP 或您的 ISP smtp 服务器应该从您的电子邮件地址或您的计算机发送邮件,但可以阻止它们。如果您能够使用邮件客户端发送邮件,请查看您使用的 smtp 服务器和参数并在 php 中使用它们。

标签: php forms email post


【解决方案1】:

您需要标题吗?如果没有,你可以试试这个代码:

mail("yourmail@mail.com","subject","The message's body");

【讨论】:

  • 现在试过了,还是不行。
  • 等一下有时需要时间。
猜你喜欢
  • 2015-12-10
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
  • 2020-09-19
  • 2013-09-19
  • 2014-09-05
  • 2013-09-04
相关资源
最近更新 更多