Computer Science Canada

Email says its from nobody

Author:  nonamedude [ Tue Nov 29, 2011 7:44 pm ]
Post subject:  Email says its from nobody

Hey guys,

Ive recently tried to use the php mail function to send out confirmation emails, and I have been successful in doing so. However, when I added a few things to my script, something doesn't seem to work.

The code below is the code that I got to work. Everything that I need for the email to contain appears.
code:
<?php
$to        = 'Myemail';
$subject = 'Confirmation';
$message = 'This is a test';
$headers = 'MIME-Version: 1.0' . "\r\n" .
    'Content-type: text/plain; charset=iso-8859-1' . "\r\n" .
    'Content-Transfer_Encoding: 7bit' . "\r\n\r\n" .
    'From: fromemail'."\r\n" . 
    'Reply-To: replyemail' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>


However when I transfer the same headers to another script (Below), the mail delivers but there are a few issues.

1) My mail says that the mail is from nobody.
2) Instead of the headers appearing in the info area, it appears as text in the mail
From: fromemail
Reply-To: reply email
X-Mailer: PHP/5.2.9

The script below is being included in another program i wrote, so i am wondering if thats the problem. I dont think its syntax because its the same headers I used above. I have attached a picture of the mail I get.
Here is a imgur link in case the attachment fails http://imgur.com/weNkr

Your help is greatly appreciated!!!

code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <HEAD>
    </HEAD>
    <body>
        <?php
        $message = $_POST['message'];
        $subject = $_POST['subject'];
        if ($message != null) {
            include("connect.php");
            $extract = mysql_query("SELECT * FROM `contact` ORDER BY `id`") or die("Error");
            $counter = 0;
            while ($row = mysql_fetch_assoc($extract)) {
                $email[$counter] = $row['email'];
                $counter++;
            }
            for ($x = 0; $x < $counter; $x++) {
                $to = $email[$x];
                $subject = $subject;
                $message = $message;
                $headers = 'MIME-Version: 1.0' . "\r\n" .
                        'Content-type: text/plain; charset=iso-8859-1' . "\r\n" .
                        'Content-Transfer_Encoding: 7bit' . "\r\n\r\n" .
                        'From: fromemail' . "\r\n" .
                        'Reply-To: replyemail' . "\r\n" .
                        'X-Mailer: PHP/' . phpversion();
                mail($to, $subject, $message, $headers);
                echo "EMAIL WAS SENT TO: ";
                echo $email[$x];
                echo "<BR>";
            }
        }
        ?>
    </body>
</html>
[/code]

Author:  Tony [ Tue Nov 29, 2011 8:01 pm ]
Post subject:  RE:Email says its from nobody

"from" is part of the header, which is not interpreted as a header. 1 and 2 are the same problem.

Author:  nonamedude [ Tue Nov 29, 2011 8:03 pm ]
Post subject:  Re: Email says its from nobody

The first chunk of code works. It says its from the correct person and everything and the headers are displayed fine too. Its the second chunk that fails to function properly.

Author:  Brightguy [ Wed Nov 30, 2011 7:38 am ]
Post subject:  Re: Email says its from nobody

In the spirit of facebombing, I present bugbombing, my favourite way of highlighting bugs.
Posted Image, might have been reduced in size. Click Image to view fullscreen.

...I am easily amused.


: