PHP mail() function not working with BCC functionality

Hi,

I am having a problem with the PHP mail() function specifically when trying to BCC or CC someone on the message.  It works without these extra headers.

scenario:

RHEL 4
PHP 4.4.4

Here is the code (e-mail addresses changed...):
/////////This is the code that doesn't work///////
$to = "blah@gmail.com";
$bodypagl = "Test BCC";
$header = "From: blah@hotmail.com";
$header .= "/r/n";
$header .="Bcc: blah@yahoo.com";
$header .= "/r/n";
mail($to, "Test BCC", $bodypagl, $header);

////This is the code that does work, but doesn't BCC////
$to = "blah@gmail.com";
$bodypagl = "Test BCC";
$header = "From: blah@hotmail.com";
$header .= "/r/n";
mail($to, "Test BCC", $bodypagl, $header);


Any help is greatly appreciated. I need to get the BCC working so we e-mails are not lost when their is turnover and we are not told about it right away to change it to send to someone new.

Thanks!
LVL 17
jrm213jrm213Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GawaiConnect With a Mentor Commented:
/r/n works but the mail address looks like
from@hotmail.com/r/n
but doest not send mail to Bcc or CC.
anyway ask to refund point or just award anyone :P
0
 
glcumminsCommented:
Does the code actually throw an error, or is the email just not received? If the email is not received, the first place you should check is spam filters. Messages received to an address via a BCC peg pretty high up on the spam filter watch lists, and sending from a PHP script without recognizable mail-software signatures probably puts the message over the top, and into the bin.
0
 
GawaiCommented:
try this as a trial

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

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


read
http://www.php.net/function.mail

0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
jrm213jrm213Author Commented:
The code does not throw an error. However, neither the recipient (to:) or the Bcc person receive the e-mail when I add in the Bcc header.

I can put the mail-software signatures in, I was just trying to keep it as simple as possible.
those are the X-Type things right?

0
 
jrm213jrm213Author Commented:
to gawai,

that is basically what I have minus the mime-version and content-type. I am not sending HTML mail it is plain text. I will add those in though and see if it helps.

I have read the function information and the comments on php.net that is why I am posting here. According to that documentation the additional headers are optional, but if you do include them it seems the only required item is FROM. So I don't understand why adding the Bcc entry is stopping the mail.

Thanks for your help
0
 
jrm213jrm213Author Commented:
Changed the code to:

$to = "someone@gmail.com";
$bodypagl = "Test BCC";
$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: someone@hotmail.com";
$header .= "/r/n";
$header .="Bcc: someone@yahoo.com";
$header .= "/r/n";
$header .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
mail($to, "Some Subject", $bodypagl, $header);

Still none of the accounts receive the mail.
0
 
hernst42Commented:
Try using a mailer-class like
http://swiftmailer.sf.net
http://phpmailer.sf.net


From http://www.php.net/manual/en/function.mail.php
    Note:  The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

    Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

    As such, the to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA.

    Note: Email with attachments and special types of
0
 
jrm213jrm213Author Commented:
Hi,

I am not interested in implementing someone elses class into this code. I am looking for a solution to the problem not a new way to send e-mail. As noted in the original post, this is Redhat Enterprise Linux 4 (RHEL 4) not windows. The addresses I am using are straight addresses blah@gmail.com etc.

I am trying to figure out why it works with the header that just has "From: blah@gmail.com"; but does not work when I add in the Bcc info. I guess if worse comes to worse I will just send another e-mail to the bcc address but that seems dumb.

-Jack
0
 
GawaiCommented:
i would like to see complete script
0
 
jrm213jrm213Author Commented:
Hi,

Ok, I figured this out.

$header .= "/r/n";
$header .="Bcc: blah@yahoo.com";
$header .= "/r/n";
$header .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

the /r/n in the above should be \r\n I had the wrong slash.
I didn't need the x-mailer, mime or content-type things.

0
 
GawaiCommented:
but your above code with /r/n  work for me lol
0
 
jrm213jrm213Author Commented:
Points will be awarded to gawai because it was looking at his code he posted that made me see the problem. They should use some character like * or # instead of / because it is too easy to use the wrong one and your brain makes it look like the right one.
0
 
ll_jaxnCommented:
Dude......

The header is specific...

You neede the CC: blank entry
0
All Courses

From novice to tech pro — start learning today.