HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Programming/Scripts (
-   -   Problem with PHP mail() (

countrydj 3rd November 2011 21:31

Problem with PHP mail()
Hi Guys...

I have a problem that I just done understand.
This is the code that I am using:

        # SEND EMAIL

//        $to      = '';
        $to      = '';
        $subject = "Web site Enquiry";

        $headers = "From: $email ($name)\r\n";
        $headers .= "Bcc:\r\n";
          $headers .="Reply-To: $name <$email>\r\n";
          $headers .="X-Mailer: PHP/ . phpversion()";

        $messages = "Message from:  $name ($email) on $date_time\n\n";
        $messages .= "-----------------------------------------------------------------------------------------------------------------------------------\n\n";
        $messages .= "Remote IP: $remote_ip\n";
        $messages .= "Referer: $referer\n\n";
        $messages .= "Name: $name\n\n";
        $messages .= "Country: $country\n\n";
        $messages .= "Selection: $selection\n\n";
        $messages .= "Message:\n";
        $messages .= "$message\n\n";
        $messages .= "-----------------------------------------------------------------------------------------------------------------------------------\n\n";
        $messages .= "HTTP_USER_AGENT: $client\n\n";
mail($to, $subject, $messages, $headers);

The problem that I have is that the code will send Bcc when I have the main recipient as:

$to      = '';
but it will NOT send Bcc when the main recipient is:

$to      = '';
Has anybody got any ideas why this should happen ???

Any suggestions will be welcome.

John C

falko 4th November 2011 11:31

Do and point to the same mailbox?

countrydj 4th November 2011 13:15

Hi Falko...
Thanks for taking the time to try and help me.

Do and point to the same mailbox?
Yes, as it happens, they do.

However, this issue came to light when I was setting up another contact form for a different site. This is what I was setting up and couldn't get it to work:
PHP Code:


$to      '';
$subject "Web site Enquiry";

$headers "From: $email ($name)\r\n";
$headers .= "Bcc:\r\n";
$headers .="Reply-To: $name <$email>\r\n";
$headers .="X-Mailer: PHP/ . phpversion()" and do NOT share the same mailbox.

When I couldn't get this to work, I went to a script that I knew was working to try and identify the problem.

I tested again with an email address that I control and doesn't go to the same mailbox.

You were RIGHT...

That worked.

I then went back to the original problem (the code above) and it was working !!!

The only thing that I did was to turn off my computer (not server) last night and switch it on agan this morning.


Thanks very much for your help...

John C

nashj99 24th November 2011 10:57

hey all,

the phpmail function is used in the php scripting for sending mail from the php code . the actuall script is
$to = "";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From:" . "\r\n" .


is this a complete code to send mail from the script ?

falko 25th November 2011 18:55

Yes, that should work.

All times are GMT +2. The time now is 00:16.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.