【问题标题】:php mail subject not send [closed]php邮件主题未发送[关闭]
【发布时间】:2015-03-27 22:37:59
【问题描述】:

我正在尝试使用 php 发送电子邮件,它运行良好,但只有我收到的消息有问题,主题不起作用。有人能找到问题吗?

  <?php
        $to = "me@email.com";
        $name = $_REQUEST['name'];
        $headers = "From: $from";
        $subject = "You have a message from $name.";
        $fields = array();
        $fields{"email"} = "email";
        $fields{"message"} = "message";
        $body = "Message:\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
        $send = mail($to, $body, $headers, $subject);
    ?>

【问题讨论】:

  • 这个问题是由无法再复制的问题或简单的印刷错误引起的。虽然类似的问题可能是这里的主题,但这个问题的解决方式不太可能帮助未来的读者。

标签: php


【解决方案1】:

尝试如下更改$send的顺序;

 $send = mail($to, $subject, $body, $headers);

更新: 感谢 David 指出,将变量 $from 添加到您的 php 中,以便发件人的电子邮件也将包含在 $headers 中:

<?php
        $to = "me@email.com";
        $from = $_REQUEST['from'];
        $name = $_REQUEST['name'];
        $headers = "From: $from";
        $subject = "You have a message from $name.";
        $fields = array();
        $fields{"email"} = "email";
        $fields{"message"} = "message";
        $body = "Message:\n\n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
        $send = mail($to, $subject, $body, $headers);
    ?>

【讨论】:

  • 另外,变量 $from 从未设置,但在第 4 行使用。
  • @David 不错!刚刚将其添加到答案中。
  • 您仍然需要修复“更新”部分中的mail 功能。
  • @David 刚刚修好了!谢谢!
猜你喜欢
  • 2013-02-05
  • 2011-12-09
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
  • 2013-04-21
  • 1970-01-01
相关资源
最近更新 更多