Problem with PHP mail()

Discussion in 'Programming/Scripts' started by countrydj, Nov 3, 2011.

  1. countrydj

    countrydj New Member

    Hi Guys...

    I have a problem that I just done understand.
    This is the code that I am using:
    Code:
    	# SEND EMAIL
    
    //	$to      = 'ann@in-uk.co.uk';
    	$to      = 'dave@swarbrick-racing.co.uk';
    	$subject = "Web site Enquiry";
    
    	$headers = "From: $email ($name)\r\n";
    	$headers .= "Bcc: jc@ukzone.com\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:
    Code:
    $to      = 'dave@swarbrick-racing.co.uk'; 
    but it will NOT send Bcc when the main recipient is:
    Code:
    $to      = 'ann@in-uk.co.uk'; 
    Has anybody got any ideas why this should happen ???

    Any suggestions will be welcome.

    John C
     
  2. falko

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    Do jc@ukzone.com and ann@in-uk.co.uk point to the same mailbox?
     
  3. countrydj

    countrydj New Member

    Hi Falko...
    Thanks for taking the time to try and help me.
    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:
        # SEND EMAIL

        
    $to      'ken@ckmarquees.co.uk';
        
    $subject "Web site Enquiry";

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

    ken@ckmarquees.co.uk and jc@ukzone.com 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.

    HOWEVER....
    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
     
  4. nashj99

    nashj99 New Member

    hey all,

    the phpmail function is used in the php scripting for sending mail from the php code . the actuall script is
    <?php
    $to = "somebody@example.com";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: webmaster@example.com" . "\r\n" .
    "CC: somebodyelse@example.com";

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

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

    falko Super Moderator Howtoforge Staff Moderator HowtoForge Supporter ISPConfig Developer

    Yes, that should work.
     

Share This Page