php邮件主题不发送

时间:2015-03-27 22:38:00

标签: php

我试图用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);
    ?>

1 个答案:

答案 0 :(得分:2)

尝试更改$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);
    ?>