I am using the PEAR Mail module to send mail. I am able to send mail just fine, with one exception. For some reason, the Cc function does not work. I see email3 being CC'ed in the mail to the original mail recipient (email2), but the person being CC'ed does not get it (email3). Does anyone have any idea why and how to fix it? The code is below:

<?php
require_once "/usr/share/pear/Mail.php";

$from = "email1@somewhere.com";
$to = "email2@somewhere.com";
$cc = "email3@somewhere.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "smtp.some-server.com";
$username = "";
$password = "";

$headers['From']=$from;
$headers['To']=$to;
$headers['Subject']=$subject;
$headers['Cc']=$cc;

$auth['host']=$host;
$auth['auth']=false;
$smtp=Mail::factory('smtp',$auth);

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail))
  {
  echo("<p>" . $mail->getMessage() . "</p>");
  }
else
  {
  echo("<p>Message successfully sent!</p>");
  }
?>

    Hi there, I've been having separate mail problems of my own, though I went the PHPMailer route, and it worked for me...

    On the other hand I downloaded the PEAR Mail package and sifted through the code...

    I'm not familiar with the mail() functions deep internals, though I've noticed capitalization in the PHPMailer internals for CC and BCC... while they were being passed to the mail() function...

    Back when the mail function worked for me, the CC worked when capitalized ... I never tried it otherwise...

    Try using

    $headers['CC']=$cc;    // capitalization of Cc to CC
    

    I don't guarantee much at all, just that there are sometimes simple reasons to complicated problems... 😕

      The mail headers don't actually route the mail. They just provide a visual of who's supposed to get the mail. It's kind of like a courtesy. You have to state who really gets the mail in the send() function. Corrected code below:

      <?php
      require_once "/usr/share/pear/Mail.php";
      
      $from = "email1@somewhere.com";
      $to = "email2@somewhere.com";
      $cc = "email3@somewhere.com";
      $subject = "Hi!";
      $body = "Hi,\n\nHow are you?";
      
      //first two lines of correction code below:
      if($cc!="")$send_to=$to . "," . $cc;
      else $send_to=$to;
      
      $host = "smtp.some-server.com";
      $username = "";
      $password = "";
      
      $headers['From']=$from;
      $headers['To']=$to;
      $headers['Subject']=$subject;
      $headers['Cc']=$cc;
      
      $auth['host']=$host;
      $auth['auth']=false;
      $smtp=Mail::factory('smtp',$auth);
      
      //send function corrected below:
      $mail = $smtp->send($send_to, $headers, $body);
      
      if (PEAR::isError($mail))
        {
        echo("<p>" . $mail->getMessage() . "</p>");
        }
      else
        {
        echo("<p>Message successfully sent!</p>");
        }
      ?> 
      
        Write a Reply...