-1

i'm trying to send email with php and it works good but only the message i receive has issue, subject don't work. Can anybody find the problem?

  <?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);
    ?>
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Patrick W
  • 41
  • 4
  • This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. – mate64 Mar 27 '15 at 23:53

1 Answers1

2

Try changing $send order as the following;

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

Update: Thanks to David for pointing out, add the variable $from to your php so the sender's email will be included in the $headers too:

<?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);
    ?>
Nima
  • 2,100
  • 2
  • 23
  • 32